ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2024-09-10 05:08:14
Exec Total Coverage
Lines: 2795 8348 33.5%
Functions: 76 289 26.3%
Branches: 2418 7214 33.5%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/version.h"
10 #include "base/zapp.h"
11 #include "dialog/info.h"
12 #include "metadata/metadata.h"
13
14 #include "base/qrs.h"
15 #include "base/dmap.h"
16 #include "base/packfile.h"
17 #include "base/cpool.h"
18 #include "base/autocombo.h"
19 #include "base/gui.h"
20 #include "base/msgstr.h"
21 #include "zc/zelda.h"
22 #include "zq/zq_class.h"
23 #include "zq/zq_misc.h"
24 #include "zq/zquest.h"
25 #include "base/qst.h"
26 #include "base/colors.h"
27 #include "tiles.h"
28 #include "zq/zquestdat.h"
29 #include "base/zsys.h"
30 #include "sprite.h"
31 #include "items.h"
32 #include "zc/zc_sys.h"
33 #include "md5.h"
34 #include "zc/zc_custom.h"
35 #include "subscr.h"
36 #include "zq/zq_strings.h"
37 #include "zq/zq_subscr.h"
38 #include "zc/ffscript.h"
39 #include "base/util.h"
40 #include "zq/zq_files.h"
41 #include "dialog/alert.h"
42 #include "slopes.h"
43 #include "drawing.h"
44 #include "zinfo.h"
45 #include "zq/render_minimap.h"
46 #include "base/mapscr.h"
47 #include <fmt/format.h>
48 #include <filesystem>
49
50 #ifdef __EMSCRIPTEN__
51 #include "base/emscripten_utils.h"
52 #endif
53
54 namespace fs = std::filesystem;
55
56 using namespace util;
57
58 extern ZModule zcm;
59 extern zcmodule moduledata;
60 extern uint8_t ViewLayer3BG, ViewLayer2BG;
61 extern int32_t LayerDitherBG, LayerDitherSz;
62 extern bool NoHighlightLayer0;
63
64 using std::string;
65 using std::pair;
66 #define EPSILON 0.01 // Define your own tolerance
67 #define FLOAT_EQ(x,v) (((v - EPSILON) < x) && (x <( v + EPSILON)))
68
69 #define COLOR_SOLID vc(4)
70 #define COLOR_SLOPE vc(13)
71 #define COLOR_LADDER vc(6)
72 //#define COLOR_EFFECT vc(10)
73
74 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
75 extern char msgbuf[MSG_NEW_SIZE*8];
76
77 extern string zScript;
78
79 9 zmap Map;
80 int32_t prv_mode=0;
81 int16_t ffposx[MAXFFCS];
82 int16_t ffposy[MAXFFCS];
83 int32_t ffprvx[MAXFFCS];
84 int32_t ffprvy[MAXFFCS];
85 void init_ffpos()
86 {
87 for (word q = 0; q < MAXFFCS; ++q)
88 {
89 ffposx[q] = -1000;
90 ffposy[q] = -1000;
91 ffprvx[q] = -10000000;
92 ffprvy[q] = -10000000;
93 }
94 }
95
96 bool save_warn=true;
97
98 int32_t COMBOPOS(int32_t x, int32_t y)
99 {
100 return (((y) & 0xF0) + ((x) >> 4));
101 }
102 int32_t COMBOPOS_B(int32_t x, int32_t y)
103 {
104 if(unsigned(x) >= 256 || unsigned(y) >= 176)
105 return -1;
106 return COMBOPOS(x,y);
107 }
108 int32_t COMBOX(int32_t pos)
109 {
110 return ((pos) % 16 * 16);
111 }
112 int32_t COMBOY(int32_t pos)
113 {
114 return ((pos) & 0xF0);
115 }
116
117 void reset_dmap(int32_t index)
118 {
119 bound(index,0,MAXDMAPS-1);
120 DMaps[index].clear();
121 DMaps[index].title = "";
122 sprintf(DMaps[index].intro, " ");
123 }
124
125 void reset_dmaps()
126 {
127 for(int32_t i=0; i<MAXDMAPS; i++)
128 reset_dmap(i);
129 }
130
131 void truncate_dmap_title(std::string& title)
132 {
133 title.resize(21, ' ');
134 }
135
136 mapscr* zmap::get_prvscr()
137 {
138 return &prvscr;
139 }
140
141
7/12
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 108 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 90 times.
✓ Branch 7 taken 18 times.
✓ Branch 8 taken 18 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 18 times.
108 zmap::zmap()
142 {
143 18 can_paste=false;
144 18 prv_cmbcycle=0;
145 18 prv_advance=0;
146 18 prv_freeze=0;
147 18 copyffc=-1;
148
149 18 memset(scrpos, 0, sizeof(scrpos));
150 18 screens=NULL;
151 18 prv_time=0;
152 18 prv_scr=0;
153 18 prv_map=0;
154 18 copyscr=0;
155 18 currscr=0;
156 18 copymap=0;
157 18 currmap=0;
158 18 layer_target_map = 0;
159 18 layer_target_scr = 0;
160 18 layer_target_multiple = 0;
161
162 18 }
163 18 zmap::~zmap()
164 {
165 18 }
166
167 9 void zmap::clear()
168 {
169
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 *this = zmap();
170 9 }
171 void zmap::force_refr_pointer()
172 {
173 if(unsigned(currmap) > map_count || (currmap*MAPSCRS > TheMaps.size()))
174 screens = nullptr;
175 else screens = &TheMaps[currmap*MAPSCRS];
176 }
177 bool zmap::CanUndo()
178 {
179 return undo_stack.size() > 0;
180 }
181 bool zmap::CanRedo()
182 {
183 return redo_stack.size() > 0;
184 }
185 bool zmap::CanPaste()
186 {
187 return can_paste;
188 }
189 int32_t zmap::CopyScr()
190 {
191 return (copymap<<8)+copyscr;
192 }
193 int32_t zmap::getCopyFFC()
194 {
195 return copyffc;
196 }
197 set_ffc_command::data_t zmap::getCopyFFCData()
198 {
199 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
200 }
201 29 int32_t zmap::getMapCount()
202 {
203 29 return map_count;
204 }
205 int32_t zmap::getLayerTargetMap()
206 {
207 return layer_target_map;
208 }
209 int32_t zmap::getLayerTargetScr()
210 {
211 return layer_target_scr;
212 }
213 int32_t zmap::getLayerTargetMultiple()
214 {
215 return layer_target_multiple;
216 }
217 bool zmap::isDungeon(int32_t scr)
218 {
219 for(int32_t i=0; i<4; i++)
220 {
221 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
222 {
223 return false;
224 }
225 }
226
227 return true;
228 }
229
230 bool zmap::clearall(bool validate)
231 {
232 Color=0;
233 char tbuf[10];
234
235 if((header.templatepath[0]!=0)&&validate)
236 {
237 if(!valid_zqt(header.templatepath))
238 {
239 jwin_alert("Error","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
240 return false;
241 }
242 }
243
244 for(int32_t i=0; i<map_count; i++)
245 {
246 setCurrMap(i);
247 sprintf(tbuf, "%d", i);
248 clearmap(true);
249 }
250
251 setCurrMap(0);
252 return true;
253 }
254
255 bool zmap::reset_templates(bool validate)
256 {
257 //why are we doing this?
258 if(colordata==NULL)
259 {
260 return false;
261 }
262
263 char *deletefilename=(char *)malloc(1);
264 ASSERT(deletefilename);
265 deletefilename[0]=0;
266
267 //int32_t ret;
268 word version, build, dummy, sversion=0;
269 byte dummyc;
270 word dummyw;
271 //int32_t section_size;
272 word temp_map_count;
273 mapscr temp_mapscr;
274 PACKFILE *f=NULL;
275
276 // setPackfilePassword(datapwd);
277 f=open_quest_template(&header, deletefilename, validate);
278 get_version_and_build(f, &version, &build);
279
280 if(!find_section(f, ID_MAPS))
281 {
282 // setPackfilePassword(NULL);
283 return false;
284 }
285
286 //section version info
287 if(!p_igetw(&sversion,f))
288 {
289 return false;
290 }
291
292 if(!p_igetw(&dummy,f))
293 {
294 return false;
295 }
296
297 //section size
298 dword dummy_size;
299 if(!p_igetl(&dummy_size,f))
300 {
301 return false;
302 }
303
304 //finally... section data
305 if(!p_igetw(&temp_map_count,f))
306 {
307 return false;
308 }
309
310 if(version>12)
311 {
312 if(!p_getc(&dummyc,f))
313 return qe_invalid;
314
315 if(!p_getc(&dummyc,f))
316 return qe_invalid;
317
318 if(!p_igetw(&dummyw,f))
319 return qe_invalid;
320
321 if(!p_igetw(&dummyw,f))
322 return qe_invalid;
323
324 if(!p_igetw(&dummyw,f))
325 return qe_invalid;
326
327 if(!p_igetw(&dummyw,f))
328 return qe_invalid;
329
330 if(!p_igetw(&dummyw,f))
331 return qe_invalid;
332
333 if(!p_igetw(&dummyw,f))
334 return qe_invalid;
335
336 if(!p_igetw(&dummyw,f))
337 return qe_invalid;
338
339 if(!p_igetw(&dummyw,f))
340 return qe_invalid;
341
342 if(!p_igetw(&dummyw,f))
343 return qe_invalid;
344
345 if(!p_igetw(&dummyw,f))
346 return qe_invalid;
347
348 if(!p_getc(&dummyc,f))
349 return qe_invalid;
350
351 if(!p_getc(&dummyc,f))
352 return qe_invalid;
353 }
354
355 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
356 {
357 readmapscreen(f, &header, &temp_mapscr, sversion);
358 }
359
360 readmapscreen(f, &header, &TheMaps[128], sversion);
361 readmapscreen(f, &header, &TheMaps[129], sversion);
362
363 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
364 {
365 readmapscreen(f, &header, &temp_mapscr, sversion);
366 }
367
368 if(version>12)
369 {
370 if(!p_getc(&dummyc,f))
371 return qe_invalid;
372
373 if(!p_getc(&dummyc,f))
374 return qe_invalid;
375
376 if(!p_igetw(&dummyw,f))
377 return qe_invalid;
378
379 if(!p_igetw(&dummyw,f))
380 return qe_invalid;
381
382 if(!p_igetw(&dummyw,f))
383 return qe_invalid;
384
385 if(!p_igetw(&dummyw,f))
386 return qe_invalid;
387
388 if(!p_igetw(&dummyw,f))
389 return qe_invalid;
390
391 if(!p_igetw(&dummyw,f))
392 return qe_invalid;
393
394 if(!p_igetw(&dummyw,f))
395 return qe_invalid;
396
397 if(!p_igetw(&dummyw,f))
398 return qe_invalid;
399
400 if(!p_igetw(&dummyw,f))
401 return qe_invalid;
402
403 if(!p_igetw(&dummyw,f))
404 return qe_invalid;
405
406 if(!p_getc(&dummyc,f))
407 return qe_invalid;
408
409 if(!p_getc(&dummyc,f))
410 return qe_invalid;
411 }
412
413 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
414 {
415 readmapscreen(f, &header, &temp_mapscr, sversion);
416 }
417
418 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
419 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
420
421 pack_fclose(f);
422 clear_quest_tmpfile();
423
424 if(deletefilename[0]==0)
425 {
426 delete_file(deletefilename);
427 }
428
429
430 return true;
431 }
432
433 bool zmap::clearmap(bool newquest)
434 {
435 if(currmap<map_count)
436 {
437 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
438 {
439 clearscr(i);
440 }
441
442 setCurrScr(0);
443
444 if(newquest)
445 {
446 if(!reset_templates(false))
447 {
448 jwin_alert("Error","Error resetting","template screens.",NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
449 }
450 }
451 }
452
453 return true;
454 }
455
456 mapscr* zmap::CurrScr()
457 {
458 return screens+currscr;
459 }
460 mapscr* zmap::Scr(int32_t scr)
461 {
462 return screens+scr;
463 }
464 mapscr* zmap::AbsoluteScr(int32_t scr)
465 {
466 if(unsigned(scr) >= MAPSCRS*getMapCount())
467 return nullptr;
468 return &TheMaps[scr];
469 }
470 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
471 {
472 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
473 return nullptr;
474 return AbsoluteScr((map*MAPSCRS)+scr);
475 }
476 void zmap::set_prvscr(int32_t map, int32_t scr)
477 {
478 prvscr=TheMaps[(map*MAPSCRS)+scr];
479
480 for(int32_t i=0; i<6; i++)
481 {
482 if(prvscr.layermap[i]>0)
483 {
484 prvlayers[i]=TheMaps[(prvscr.layermap[i]-1)*MAPSCRS+prvscr.layerscreen[i]];
485 }
486 else
487 prvlayers[i].valid = 0;
488 }
489
490 prv_map=map;
491 prv_scr=scr;
492 }
493 71 int32_t zmap::getCurrMap()
494 {
495 71 return currmap;
496 }
497 bool zmap::isDark()
498 {
499 return (screens[currscr].flags&fDARK)!=0;
500 }
501
502 void zmap::setCurrentView(int32_t map, int32_t scr)
503 {
504 bool change_view = map != Map.getCurrMap() || scr != Map.getCurrScr();
505 if (map != Map.getCurrMap()) Map.setCurrMap(map);
506 if (scr != Map.getCurrScr()) Map.setCurrScr(scr);
507 if (change_view)
508 {
509 refresh(rALL);
510 rebuild_trans_table();
511 }
512 }
513
514 9 void zmap::setCurrMap(int32_t index)
515 {
516 9 int32_t oldmap=currmap;
517 9 optional<int> oldcolor;
518
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(screens)
519 oldcolor = getcolor();
520 9 scrpos[currmap]=currscr;
521 9 currmap=bound(index,0,map_count);
522 9 screens=&TheMaps[currmap*MAPSCRS];
523
524 9 currscr=scrpos[currmap];
525 9 int newcolor = getcolor();
526 9 loadlvlpal(newcolor);
527
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(!oldcolor || *oldcolor != newcolor)
528 9 rebuild_trans_table();
529
530 9 reset_combo_animations2();
531 9 mmap_mark_dirty();
532 9 }
533
534 17 int32_t zmap::getCurrScr()
535 {
536 17 return currscr;
537 }
538 9 void zmap::setCurrScr(int32_t scr)
539 {
540
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
9 if(scr==currscr) return;
541
542 8 int32_t oldscr=currscr;
543 8 int32_t oldcolor=getcolor();
544
545
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 if(!(screens[currscr].valid&mVALID))
546 {
547 2 oldcolor=-1;
548 2 }
549
550 8 currscr=bound(scr,0,MAPSCRS-1);
551 8 int32_t newcolor=getcolor();
552 8 loadlvlpal(newcolor);
553
554 //setcolor(newcolor);
555
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!(screens[currscr].valid&mVALID))
556 {
557 newcolor=-1;
558 }
559
560
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
8 if(newcolor!=oldcolor)
561 {
562 7 rebuild_trans_table();
563 7 }
564
565 8 reset_combo_animations2();
566 8 setlayertarget();
567 8 mmap_mark_dirty();
568 9 }
569
570 8 void zmap::setlayertarget()
571 {
572 8 layer_target_map = 0;
573 8 layer_target_multiple = 0;
574
575
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 8 times.
29 for(int32_t m=0; m<getMapCount(); ++m)
576 {
577
2/2
✓ Branch 0 taken 2856 times.
✓ Branch 1 taken 21 times.
2877 for(int32_t s=0; s<MAPSCRS; ++s)
578 {
579 2856 int32_t i=(m*MAPSCRS+s);
580 2856 mapscr *ts=&TheMaps[i];
581
582 // Search through each layer
583
2/2
✓ Branch 0 taken 17136 times.
✓ Branch 1 taken 2856 times.
19992 for(int32_t w=0; w<6; ++w)
584 {
585
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 17134 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
17136 if(ts->layerscreen[w]==currscr && (ts->layermap[w]-1)==currmap)
586 {
587 if(layer_target_map > 0)
588 {
589 layer_target_multiple += 1;
590 continue;
591 }
592
593 layer_target_map = m+1;
594 layer_target_scr = s;
595 }
596 17136 }
597 2856 }
598 21 }
599 8 }
600
601 void zmap::setcolor(int32_t c)
602 {
603 screens[currscr].valid |= mVALID;
604 screens[currscr].color = c;
605
606 if(Color!=c)
607 {
608 Color = c;
609 loadlvlpal(c);
610 rebuild_trans_table();
611 }
612
613 mmap_mark_dirty();
614 }
615
616 25 int32_t zmap::getcolor()
617 {
618
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 if(prv_mode)
619 {
620 return prvscr.color;
621 }
622
623 25 return screens[currscr].color;
624 25 }
625
626 void zmap::resetflags()
627 {
628 byte *di=&(screens[currscr].valid);
629
630 for(int32_t i=1; i<48; i++)
631 {
632 *(di+i)=0;
633 }
634 }
635
636 word zmap::tcmbdat(int32_t pos)
637 {
638 return screens[TEMPLATE].data[pos];
639 }
640
641 word zmap::tcmbcset(int32_t pos)
642 {
643 return screens[TEMPLATE].cset[pos];
644 }
645
646 int32_t zmap::tcmbflag(int32_t pos)
647 {
648 return screens[TEMPLATE].sflag[pos];
649 }
650
651 word zmap::tcmbdat2(int32_t pos)
652 {
653 return screens[TEMPLATE2].data[pos];
654 }
655
656 word zmap::tcmbcset2(int32_t pos)
657 {
658 return screens[TEMPLATE2].cset[pos];
659 }
660
661 int32_t zmap::tcmbflag2(int32_t pos)
662 {
663 return screens[TEMPLATE2].sflag[pos];
664 }
665
666 void zmap::TemplateAll()
667 {
668 StartListCommand();
669 for(int32_t i=0; i<128; i++)
670 {
671 if((screens[i].valid&mVALID) && isDungeon(i))
672 DoTemplateCommand(-1, i, currscr);
673 }
674 FinishListCommand();
675 }
676
677 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
678 {
679 if(scr==TEMPLATE)
680 return;
681
682 if(!(screens[scr].valid&mVALID))
683 screens[scr].color=Color;
684
685 screens[scr].valid|=mVALID;
686
687 for(int32_t i=0; i<32; i++)
688 {
689 screens[scr].data[i]=screens[TEMPLATE].data[i];
690 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
691 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
692 }
693
694 for(int32_t i=144; i<176; i++)
695 {
696 screens[scr].data[i]=screens[TEMPLATE].data[i];
697 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
698 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
699 }
700
701 for(int32_t y=2; y<=9; y++)
702 {
703 int32_t j=y<<4;
704 screens[scr].data[j]=screens[TEMPLATE].data[j];
705 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
706 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
707 ++j;
708 screens[scr].data[j]=screens[TEMPLATE].data[j];
709 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
710 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
711 ++j;
712 j+=12;
713 screens[scr].data[j]=screens[TEMPLATE].data[j];
714 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
715 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
716 ++j;
717 screens[scr].data[j]=screens[TEMPLATE].data[j];
718 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
719
720 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
721 ++j;
722 }
723
724 if(floorcombo!=-1)
725 {
726 for(int32_t y=2; y<9; y++)
727 for(int32_t x=2; x<14; x++)
728 {
729 int32_t i=(y<<4)+x;
730 screens[scr].data[i] = floorcombo;
731 screens[scr].cset[i] = floorcset;
732 }
733 }
734
735 for(int32_t i=0; i<4; i++)
736 putdoor(scr,i,screens[scr].door[i]);
737 }
738
739
740 void zmap::clearscr(int32_t scr)
741 {
742 screens[scr].zero_memory();
743 screens[scr].valid=mVERSION;
744 for(int q = 0; q < 6; ++q)
745 {
746 auto layer = map_autolayers[currmap*6+q];
747 screens[scr].layermap[q] = layer;
748 screens[scr].layerscreen[q] = layer ? scr : 0;
749 }
750 mmap_mark_dirty();
751 }
752
753 const char *loaderror[] =
754 {
755
756 "OK","File not found","Incomplete data",
757 "Invalid version","Invalid file"
758
759 };
760
761 int32_t zmap::load(const char *path)
762 {
763 PACKFILE *f=pack_fopen_password(path,F_READ, "");
764
765 if(!f)
766 return 1;
767
768
769 int16_t version;
770 byte build;
771
772 //get the version
773 if(!p_igetw(&version,f))
774 {
775 goto file_error;
776 }
777
778 //get the build
779 if(!p_getc(&build,f))
780 {
781 goto file_error;
782 }
783
784 for(int32_t i=0; i<MAPSCRS; i++)
785 {
786 mapscr tmpimportscr;
787 tmpimportscr.zero_memory();
788 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
789 {
790 al_trace("failed zmap::load\n");
791 goto file_error;
792 }
793
794 switch(ImportMapBias)
795 {
796 case 0:
797 *(screens+i) = tmpimportscr;
798 break;
799
800 case 1:
801 if(!(screens[i].valid&mVALID))
802 {
803 *(screens+i) = tmpimportscr;
804 }
805 break;
806
807 case 2:
808 if(tmpimportscr.valid&mVALID)
809 {
810 *(screens+i) = tmpimportscr;
811 }
812 break;
813 }
814 }
815
816
817 pack_fclose(f);
818
819 setCurrScr(0);
820 mmap_mark_dirty();
821 return 0;
822
823 file_error:
824 pack_fclose(f);
825 clearmap(false);
826 return 2;
827 }
828
829 int32_t zmap::save(const char *path)
830 {
831 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
832
833 if(!f)
834 return 1;
835
836 if(!p_iputw(V_MAPS,f))
837 {
838 pack_fclose(f);
839 return 3;
840 }
841
842 // This was the "build number", but that's totally useless here. Keep this junk byte
843 // so as not to totally break exports between ZC versions.
844 if(!p_putc(0,f))
845 {
846 pack_fclose(f);
847 return 3;
848 }
849
850 for(int32_t i=0; i<MAPSCRS; i++)
851 {
852 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
853 {
854 pack_fclose(f);
855 return 2;
856 }
857 }
858
859 pack_fclose(f);
860 return 0;
861 }
862
863
864 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
865 {
866 // Hookshots can be blocked by solid combos on all 3 ground layers.
867 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
868
869 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
870 return true;
871 if (c->walk&(1<<i))
872 return false;
873
874 for(int32_t k=0; k<2; k++)
875 {
876 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
877
878 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
879 {
880 return false;
881 }
882 }
883
884 return true;
885 }
886
887 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
888 {
889 // Hookshots can be blocked by solid combos on all 3 ground layers.
890 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
891
892 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
893 return true;
894 if (c->walk&(1<<i))
895 return false;
896
897 for(int32_t k=0; k<2; k++)
898 {
899 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
900
901 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
902 {
903 return false;
904 }
905 }
906
907 return true;
908 }
909
910 bool zmap::isstepable(int32_t combo)
911 {
912 // This is kind of odd but it's true to the engine (see maps.cpp)
913 return (combo_class_buf[combobuf[combo].type].ladder_pass);
914 }
915
916 // Returns the letter of the warp combo.
917 int32_t zmap::warpindex(int32_t combo)
918 {
919 switch(combobuf[combo].type)
920 {
921 case cCAVE:
922 case cPIT:
923 case cSTAIR:
924 case cCAVE2:
925 case cSWIMWARP:
926 case cDIVEWARP:
927 case cSWARPA:
928 return 0;
929
930 case cCAVEB:
931 case cPITB:
932 case cSTAIRB:
933 case cCAVE2B:
934 case cSWIMWARPB:
935 case cDIVEWARPB:
936 case cSWARPB:
937 return 1;
938
939 case cCAVEC:
940 case cPITC:
941 case cSTAIRC:
942 case cCAVE2C:
943 case cSWIMWARPC:
944 case cDIVEWARPC:
945 case cSWARPC:
946 return 2;
947
948 case cCAVED:
949 case cPITD:
950 case cSTAIRD:
951 case cCAVE2D:
952 case cSWIMWARPD:
953 case cDIVEWARPD:
954 case cSWARPD:
955 return 3;
956
957 case cPITR:
958 case cSTAIRR:
959 case cSWARPR:
960 return 4;
961 }
962
963 return -1;
964
965 }
966
967 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
968 {
969 if(top)
970 line(dest,x,y,x+15,y,c);
971 rectfill(dest,x,y,x+3,y+15,c);
972 rectfill(dest,x+12,y,x+15,y+15,c);
973 rectfill(dest,x+4,y+2,x+11,y+5,c);
974 rectfill(dest,x+4,y+10,x+11,y+13,c);
975 }
976
977 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
978 {
979 line(dest,x,y,x+15,y,c);
980 }
981
982 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
983 {
984 int32_t cx = COMBOX(pos);
985 int32_t cy = COMBOY(pos);
986
987 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
988
989 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
990
991 int32_t bridgedetected = 0;
992
993 for(int32_t i=0; i<4; i++)
994 {
995 int32_t tx=((i&2)<<2)+x;
996 int32_t ty=((i&1)<<3)+y;
997 int32_t tx2=((i&2)<<2)+cx;
998 int32_t ty2=((i&1)<<3)+cy;
999 for (int32_t m = layer; m <= 1; m++)
1000 {
1001 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1002 {
1003 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1004 {
1005 bridgedetected |= (1<<i);
1006 }
1007 }
1008 else
1009 {
1010 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1011 {
1012 bridgedetected |= (1<<i);
1013 }
1014 }
1015 }
1016 if (bridgedetected & (1<<i))
1017 {
1018 if (i >= 3) break;
1019 else continue;
1020 }
1021 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1022 {
1023 for(int32_t k=0; k<8; k+=2)
1024 for(int32_t j=0; j<8; j+=2)
1025 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1026 }
1027 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1028 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1029
1030 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1031 {
1032 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1033 {
1034 for(int32_t k=0; k<8; k+=2)
1035 for(int32_t j=0; j<8; j+=2)
1036 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1037 }
1038 else
1039 {
1040 int32_t color = COLOR_SOLID;
1041
1042 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1043 color=vc(6);
1044 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1045 color=vc(7);
1046
1047 rectfill(dest,tx,ty,tx+7,ty+7,color);
1048 }
1049 }
1050 }
1051
1052 bridgedetected = 0;
1053 for(int32_t i=0; i<4; i++)
1054 {
1055 int32_t tx2=((i&2)<<2)+cx;
1056 int32_t ty2=((i&1)<<3)+cy;
1057 for (int32_t m = 0; m <= 1; m++)
1058 {
1059 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1060 {
1061 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1062 {
1063 bridgedetected |= (1<<i);
1064 }
1065 }
1066 else
1067 {
1068 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1069 {
1070 bridgedetected |= (1<<i);
1071 }
1072 }
1073 }
1074 }
1075
1076 // Draw damage combos
1077 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1078 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1079 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1080 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1081 || combo_class_buf[c1.type].modify_hp_amount
1082 || combo_class_buf[c2.type].modify_hp_amount;
1083
1084 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1085
1086 if(dmg)
1087 {
1088 if (bridgedetected <= 0)
1089 {
1090 for(int32_t k=0; k<16; k+=2)
1091 for(int32_t j=0; j<16; j+=2)
1092 if(((k+j)/2)%2)
1093 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1094 }
1095 else
1096 {
1097 for(int32_t i=0; i<4; i++)
1098 {
1099 if (!(bridgedetected & (1<<i)))
1100 {
1101 int32_t tx=((i&2)<<2)+x;
1102 int32_t ty=((i&1)<<3)+y;
1103 for(int32_t k=0; k<8; k+=2)
1104 for(int32_t j=0; j<8; j+=2)
1105 if(((k+j)/2)%2)
1106 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1107 }
1108 }
1109 }
1110 }
1111
1112 if(c.type == cSLOPE)
1113 {
1114 slope_info s(c, x, y);
1115 s.draw(dest, 0, 0, COLOR_SLOPE);
1116 }
1117 auto fl0 = MAPFLAG2(-1,cx,cy);
1118 auto fl1 = MAPFLAG2(0,cx,cy);
1119 auto fl2 = MAPFLAG2(1,cx,cy);
1120 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1121 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1122 {
1123 bool top = false;
1124 if(cy)
1125 {
1126 top = true;
1127 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1128 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1129 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1130 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1131 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1132 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1133 {
1134 top = false;
1135 }
1136 }
1137 draw_ladder(dest,x,y,COLOR_LADDER,top);
1138 }
1139 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1140 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1141 {
1142 draw_platform(dest,x,y,COLOR_LADDER);
1143 }
1144 }
1145
1146 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1147 {
1148 int32_t cx = COMBOX(pos);
1149 int32_t cy = COMBOY(pos);
1150
1151 if (screen < 0) return;
1152 if (map < 0) return;
1153
1154 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1155
1156 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1157
1158 int32_t bridgedetected = 0;
1159 for(int32_t i=0; i<4; i++)
1160 {
1161 int32_t tx=((i&2)<<2)+x;
1162 int32_t ty=((i&1)<<3)+y;
1163 int32_t tx2=((i&2)<<2)+cx;
1164 int32_t ty2=((i&1)<<3)+cy;
1165 for (int32_t m = layer; m <= 1; m++)
1166 {
1167 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1168 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1169 {
1170 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1171 {
1172 bridgedetected |= (1<<i);
1173 }
1174 }
1175 else
1176 {
1177 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1178 {
1179 bridgedetected |= (1<<i);
1180 }
1181 }
1182 }
1183 if (bridgedetected & (1<<i))
1184 {
1185 continue;
1186 }
1187 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1188 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1189
1190
1191 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1192 {
1193 for(int32_t k=0; k<8; k+=2)
1194 for(int32_t j=0; j<8; j+=2)
1195 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1196 }
1197 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1198 {
1199 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1200 {
1201 for(int32_t k=0; k<8; k+=2)
1202 for(int32_t j=0; j<8; j+=2)
1203 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1204 }
1205 else
1206 {
1207 int32_t color = COLOR_SOLID;
1208
1209 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1210 color=vc(6);
1211 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1212 color=vc(7);
1213
1214 rectfill(dest,tx,ty,tx+7,ty+7,color);
1215 }
1216 }
1217 }
1218
1219 bridgedetected = 0;
1220 for(int32_t i=0; i<4; i++)
1221 {
1222 int32_t tx2=((i&2)<<2)+cx;
1223 int32_t ty2=((i&1)<<3)+cy;
1224 for (int32_t m = 0; m <= 1; m++)
1225 {
1226 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1227 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1228 {
1229 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1230 {
1231 bridgedetected |= (1<<i);
1232 }
1233 }
1234 else
1235 {
1236 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1237 {
1238 bridgedetected |= (1<<i);
1239 }
1240 }
1241 }
1242 }
1243
1244 // Draw damage combos
1245 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1246 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1247 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1248 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1249 || combo_class_buf[c1.type].modify_hp_amount
1250 || combo_class_buf[c2.type].modify_hp_amount;
1251
1252 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1253
1254 if(dmg)
1255 {
1256 if (bridgedetected <= 0)
1257 {
1258 for(int32_t k=0; k<16; k+=2)
1259 for(int32_t j=0; j<16; j+=2)
1260 if(((k+j)/2)%2)
1261 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1262 }
1263 else
1264 {
1265 for(int32_t i=0; i<4; i++)
1266 {
1267 if (!(bridgedetected & (1<<i)))
1268 {
1269 int32_t tx=((i&2)<<2)+x;
1270 int32_t ty=((i&1)<<3)+y;
1271 for(int32_t k=0; k<8; k+=2)
1272 for(int32_t j=0; j<8; j+=2)
1273 if(((k+j)/2)%2)
1274 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1275 }
1276 }
1277 }
1278 }
1279
1280 if(c.type == cSLOPE)
1281 {
1282 slope_info s(c, x, y);
1283 s.draw(dest, 0, 0, COLOR_SLOPE);
1284 }
1285 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1286 auto fl1 = MAPFLAG3(map,screen,0,pos);
1287 auto fl2 = MAPFLAG3(map,screen,1,pos);
1288 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1289 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1290 {
1291 bool top = false;
1292 if(cy)
1293 {
1294 top = true;
1295 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1296 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1297 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1298 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1299 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1300 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1301 {
1302 top = false;
1303 }
1304 }
1305 draw_ladder(dest,x,y,COLOR_LADDER,top);
1306 }
1307 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1308 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1309 {
1310 draw_platform(dest,x,y,COLOR_LADDER);
1311 }
1312 }
1313
1314 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1315 {
1316 const newcombo& c = combobuf[cmbdat];
1317
1318 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1319
1320 for(int32_t i=0; i<4; i++)
1321 {
1322 int32_t tx=((i&2)<<2)+x;
1323 int32_t ty=((i&1)<<3)+y;
1324
1325 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1326 {
1327 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1328 {
1329 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1330 }
1331 else
1332 {
1333 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1334 }
1335 }
1336
1337
1338 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1339 {
1340 for(int32_t k=0; k<8; k+=2)
1341 for(int32_t j=0; j<8; j+=2)
1342 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1343 }
1344 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1345 {
1346 if(c.type==cLADDERHOOKSHOT)
1347 {
1348 for(int32_t k=0; k<8; k+=2)
1349 for(int32_t j=0; j<8; j+=2)
1350 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1351 }
1352 else
1353 {
1354 int32_t color = COLOR_SOLID;
1355
1356 if(c.type==cLADDERONLY)
1357 color=vc(6);
1358 else if(c.type==cHOOKSHOTONLY)
1359 color=vc(7);
1360
1361 rectfill(dest,tx,ty,tx+7,ty+7,color);
1362 }
1363 }
1364
1365 // Draw damage combos
1366 if(combo_class_buf[c.type].modify_hp_amount != 0)
1367 {
1368 for(int32_t k=0; k<8; k+=2)
1369 for(int32_t j=0; j<8; j+=2)
1370 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1371 }
1372 }
1373
1374 if(c.type == cSLOPE)
1375 {
1376 slope_info s(c, 0, 0);
1377 zfix const& slope = s.slope();
1378
1379 BITMAP* sub = create_bitmap_ex(8,16,16);
1380 clear_bitmap(sub);
1381 s.draw(sub, 0, 0, COLOR_SLOPE);
1382 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1383 destroy_bitmap(sub);
1384 }
1385 if(c.flag == mfSIDEVIEWLADDER)
1386 {
1387 draw_ladder(dest,x,y,COLOR_LADDER);
1388 }
1389 else if(c.flag == mfSIDEVIEWPLATFORM)
1390 {
1391 draw_platform(dest,x,y,COLOR_LADDER);
1392 }
1393 }
1394
1395 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1396 {
1397 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1398 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1399 }
1400 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1401 {
1402
1403 newcombo const& c = combobuf[cmbdat];
1404
1405 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1406 {
1407 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1408 // text_mode(-1);
1409 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1410 if(sflag)
1411 {
1412 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1413 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1414 }
1415
1416 if(c.flag)
1417 {
1418 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1419 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1420 }
1421 }
1422
1423 if(flags&cCSET)
1424 {
1425 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1426 // text_mode(inv?vc(15):vc(0));
1427 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1428 }
1429 else if(flags&cCTYPE)
1430 {
1431 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1432 // text_mode(inv?vc(15):vc(0));
1433 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1434 }
1435 }
1436
1437 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1438 {
1439 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1440
1441 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1442 if(repos)
1443 {
1444 combotile_override_x = x+(8*(scale-1));
1445 combotile_override_y = y+(8*(scale-1));
1446 }
1447 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1448 if(repos) combotile_override_x = combotile_override_y = -1;
1449 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1450 destroy_bitmap(b);
1451 }
1452 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1453 {
1454 static newcombo nilcombo;
1455 nilcombo.tile = 0;
1456
1457 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1458
1459 if(c.tile==0)
1460 {
1461 rectfill(dest,x,y,x+15,y+15,vc(0));
1462 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1463 return;
1464 }
1465
1466 putcombo(dest,x,y,cmbdat,cset);
1467
1468 /* moved to put_walkflags
1469 for(int32_t i=0; i<4; i++) {
1470
1471 int32_t tx=((i&2)<<2)+x;
1472 int32_t ty=((i&1)<<3)+y;
1473 if((flags&cWALK) && (c.walk&(1<<i)))
1474 rectfill(dest,tx,ty,tx+7,ty+7,COLOR_SOLID);
1475 }
1476 */
1477
1478 // if((flags&cFLAGS)&&(cmbdat&0xF800))
1479 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1480 {
1481 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1482 // text_mode(-1);
1483 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1484 if(sflag)
1485 {
1486 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1487 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1488 }
1489
1490 if(combobuf[cmbdat].flag)
1491 {
1492 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1493 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1494 }
1495 }
1496
1497 if(flags&cWALK)
1498 {
1499 put_walkflags(dest,x,y,cmbdat,0);
1500 }
1501
1502 if(flags&cCSET)
1503 {
1504 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1505 // text_mode(inv?vc(15):vc(0));
1506 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1507 }
1508 else if(flags&cCTYPE)
1509 {
1510 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1511 // text_mode(inv?vc(15):vc(0));
1512 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1513 }
1514 }
1515 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1516 {
1517 auto blitx = 1 + (slot % 16) * 17;
1518 auto blity = 1 + (slot / 16) * 17;
1519 masked_stretch_blit((BITMAP*)zcdata[BMP_ENGRAVINGS].dat, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1520 }
1521
1522
1523 void copy_mapscr(mapscr *dest, const mapscr *src)
1524 {
1525 if(!dest || !src) return;
1526 *dest = *src;
1527 }
1528
1529 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1530 {
1531 int32_t x=0,y=0;
1532 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1533
1534 switch(side)
1535 {
1536 case up:
1537 case down:
1538 x=((pos&15)<<4)+xofs;
1539 y=(ignorepos?0:(pos&0xF0))+yofs;
1540 break;
1541
1542 case left:
1543 case right:
1544 x=(ignorepos?0:((pos&15)<<4))+xofs;
1545 y=(pos&0xF0)+yofs;
1546 break;
1547 }
1548
1549 switch(type)
1550 {
1551 case dt_lock:
1552 case dt_shut:
1553 case dt_boss:
1554 case dt_bomb:
1555 switch(side)
1556 {
1557 case up:
1558 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1559 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1560 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1561 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1562 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1563 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1564 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1565 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1566 break;
1567
1568 case down:
1569 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1570 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1571 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1572 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1573 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1574 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1575 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1576 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1577 break;
1578
1579 case left:
1580 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1581 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1582 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1583 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1584 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1585 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1586
1587 if(x+16 >= dest->w)
1588 break;
1589
1590 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1591 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1592 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1593 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1594 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1595 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1596 break;
1597
1598 case right:
1599
1600 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1601 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1602 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1603 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1604 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1605 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1606
1607 if(x+16 <= 0)
1608 break;
1609
1610 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1611 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1612 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1613 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1614 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1615 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1616 break;
1617 }
1618
1619 break;
1620
1621 case dt_pass:
1622 case dt_wall:
1623 case dt_walk:
1624 default:
1625 break;
1626 }
1627 }
1628
1629 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1630 {
1631 int32_t x=((pos&15)<<4)+xofs;
1632 int32_t y=(pos&0xF0)+yofs;
1633 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1634
1635
1636 switch(side)
1637 {
1638 case up:
1639 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1640 {
1641 overcombo(dest,x,y,
1642 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1643 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1644 }
1645
1646 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1647 {
1648 overcombo(dest,x+16,y,
1649 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1650
1651 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1652 }
1653
1654 break;
1655
1656 case down:
1657 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1658 {
1659 overcombo(dest,x,y,
1660 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1661 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1662 }
1663
1664 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1665 {
1666 overcombo(dest,x+16,y,
1667 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1668 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1669 }
1670
1671 break;
1672
1673 case left:
1674 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1675 {
1676 overcombo(dest,x,y,
1677 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1678 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1679 }
1680
1681 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1682 {
1683 overcombo(dest,x,y+16,
1684 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1685 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1686 }
1687
1688 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1689 {
1690 overcombo(dest,x,y+32,
1691 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1692 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1693 }
1694
1695 break;
1696
1697 case right:
1698 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1699 {
1700 overcombo(dest,x,y,
1701 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1702 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1703 }
1704
1705 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1706 {
1707 overcombo(dest,x,y+16,
1708
1709 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1710 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1711 }
1712
1713 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1714 {
1715 overcombo(dest,x,y+32,
1716 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1717 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1718 }
1719
1720 break;
1721 }
1722 }
1723
1724 bool zmap::misaligned(int32_t map, int32_t scr, int32_t i, int32_t dir)
1725 {
1726 word cmbcheck1, cmbcheck2;
1727 newcombo combocheck1, combocheck2;
1728 combocheck1 = combobuf[0];
1729 combocheck2 = combobuf[0];
1730 combocheck1.walk = 0;
1731 combocheck2.walk = 0;
1732
1733 int32_t layermap, layerscreen;
1734
1735 switch(dir)
1736 {
1737 case up:
1738 {
1739 if(i>15) //not top row of combos
1740 {
1741 return false;
1742 }
1743
1744 if(scr<16) //top row of screens
1745 {
1746 return false;
1747
1748 }
1749
1750 //check main screen
1751 cmbcheck1 = vbound(AbsoluteScr(map, scr)->data[i], 0, MAXCOMBOS-1);
1752 cmbcheck2 = vbound(AbsoluteScr(map, scr-16)->data[i+160], 0, MAXCOMBOS-1);
1753 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1754 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1755
1756 //check layer 1
1757 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1758
1759 if(layermap>-1 && layermap<map_count)
1760 {
1761 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1762 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1763 if (combobuf[cmbcheck1].type == cBRIDGE)
1764 {
1765 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1766 {
1767 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1768 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1769 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1770 }
1771 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1772 }
1773 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1774 }
1775
1776 layermap=AbsoluteScr(map, scr-16)->layermap[0]-1;
1777
1778 if(layermap>-1 && layermap<map_count)
1779 {
1780 layerscreen=AbsoluteScr(map, scr-16)->layerscreen[0];
1781 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1782 if (combobuf[cmbcheck2].type == cBRIDGE)
1783 {
1784 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1785 {
1786 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1787 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1788 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1789 }
1790 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1791 }
1792 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1793 }
1794
1795 //check layer 2
1796 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
1797
1798 if(layermap>-1 && layermap<map_count)
1799 {
1800 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
1801
1802 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1803 if (combobuf[cmbcheck2].type == cBRIDGE)
1804 {
1805 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1806 {
1807 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1808 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1809 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1810 }
1811 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1812 }
1813 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1814 }
1815
1816 layermap=AbsoluteScr(map, scr-16)->layermap[1]-1;
1817
1818 if(layermap>-1 && layermap<map_count)
1819 {
1820 layerscreen=AbsoluteScr(map, scr-16)->layerscreen[1];
1821 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1822 if (combobuf[cmbcheck2].type == cBRIDGE)
1823 {
1824 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1825 {
1826 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1827 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1828 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1829 }
1830 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1831 }
1832 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1833 }
1834
1835 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1836 {
1837 return true;
1838 }
1839
1840 break;
1841 }
1842 case down:
1843 {
1844 if(i<160) //not bottom row of combos
1845 {
1846 return false;
1847 }
1848
1849 if(scr>111) //bottom row of screens
1850 {
1851 return false;
1852 }
1853
1854 //check main screen
1855 cmbcheck1 = vbound(AbsoluteScr(map, scr)->data[i], 0, MAXCOMBOS-1);
1856 cmbcheck2 = vbound(AbsoluteScr(map, scr+16)->data[i-160], 0, MAXCOMBOS-1);
1857 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1858 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1859
1860
1861 //check layer 1
1862 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1863
1864 if(layermap>-1 && layermap<map_count)
1865 {
1866 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1867 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1868 if (combobuf[cmbcheck1].type == cBRIDGE)
1869 {
1870 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1871 {
1872 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1873 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1874 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1875 }
1876 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1877 }
1878 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1879 }
1880
1881 layermap=AbsoluteScr(map, scr+16)->layermap[0]-1;
1882
1883 if(layermap>-1 && layermap<map_count)
1884 {
1885 layerscreen=AbsoluteScr(map, scr+16)->layerscreen[0];
1886 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1887 if (combobuf[cmbcheck2].type == cBRIDGE)
1888 {
1889 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1890 {
1891 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1892 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1893 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1894 }
1895 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1896 }
1897 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1898 }
1899
1900 //check layer 2
1901 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
1902
1903 if(layermap>-1 && layermap<map_count)
1904 {
1905 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
1906 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1907 if (combobuf[cmbcheck1].type == cBRIDGE)
1908 {
1909 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1910 {
1911 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1912 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1913 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1914 }
1915 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1916 }
1917 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1918 }
1919
1920 layermap=AbsoluteScr(map, scr+16)->layermap[1]-1;
1921
1922 if(layermap>-1 && layermap<map_count)
1923 {
1924 layerscreen=AbsoluteScr(map, scr+16)->layerscreen[1];
1925 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1926 if (combobuf[cmbcheck2].type == cBRIDGE)
1927 {
1928 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1929 {
1930 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1931 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1932 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1933 }
1934 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1935 }
1936 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1937 }
1938
1939 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
1940 {
1941 return true;
1942 }
1943
1944 break;
1945 }
1946 case left:
1947 {
1948 if((i&0xF)!=0) //not left column of combos
1949 {
1950 return false;
1951 }
1952
1953 if((scr&0xF)==0) //left column of screens
1954 {
1955 return false;
1956 }
1957
1958 //check main screen
1959 cmbcheck1 = AbsoluteScr(map, scr)->data[i];
1960 cmbcheck2 = AbsoluteScr(map, scr-1)->data[i+15];
1961 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1962 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1963
1964 //check layer 1
1965 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1966
1967 if(layermap>-1 && layermap<map_count)
1968 {
1969 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1970 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1971 if (combobuf[cmbcheck1].type == cBRIDGE)
1972 {
1973 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1974 {
1975 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1976 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1977 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1978 }
1979 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1980 }
1981 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1982 }
1983
1984 layermap=AbsoluteScr(map, scr-1)->layermap[0]-1;
1985
1986 if(layermap>-1 && layermap<map_count)
1987 {
1988 layerscreen=AbsoluteScr(map, scr-1)->layerscreen[0];
1989 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
1990 if (combobuf[cmbcheck2].type == cBRIDGE)
1991 {
1992 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1993 {
1994 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1995 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1996 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1997 }
1998 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1999 }
2000 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2001 }
2002
2003 //check layer 2
2004 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
2005
2006 if(layermap>-1 && layermap<map_count)
2007 {
2008 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
2009 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2010 if (combobuf[cmbcheck1].type == cBRIDGE)
2011 {
2012 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2013 {
2014 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2015 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2016 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2017 }
2018 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2019 }
2020 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2021 }
2022
2023 layermap=AbsoluteScr(map, scr-1)->layermap[1]-1;
2024
2025 if(layermap>-1 && layermap<map_count)
2026 {
2027 layerscreen=AbsoluteScr(map, scr-1)->layerscreen[1];
2028 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2029 if (combobuf[cmbcheck2].type == cBRIDGE)
2030 {
2031 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2032 {
2033 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2034 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2035 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2036 }
2037 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2038 }
2039 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2040 }
2041
2042 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2043 {
2044 return true;
2045 }
2046
2047 break;
2048 }
2049 case right:
2050 {
2051 if((i&0xF)!=15) //not right column of combos
2052 {
2053 return false;
2054 }
2055
2056 if((scr&0xF)==15) //right column of screens
2057 {
2058 return false;
2059 }
2060
2061 //check main screen
2062 cmbcheck1 = AbsoluteScr(map, scr)->data[i];
2063 cmbcheck2 = AbsoluteScr(map, scr+1)->data[i-15];
2064 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2065 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2066
2067 //check layer 1
2068 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
2069
2070 if(layermap>-1 && layermap<map_count)
2071 {
2072 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
2073 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2074 if (combobuf[cmbcheck1].type == cBRIDGE)
2075 {
2076 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2077 {
2078 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2079 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2080 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2081 }
2082 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2083 }
2084 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2085 }
2086
2087 layermap=AbsoluteScr(map, scr+1)->layermap[0]-1;
2088
2089 if(layermap>-1 && layermap<map_count)
2090 {
2091 layerscreen=AbsoluteScr(map, scr+1)->layerscreen[0];
2092 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2093 if (combobuf[cmbcheck2].type == cBRIDGE)
2094 {
2095 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2096 {
2097 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2098 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2099 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2100 }
2101 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2102 }
2103 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2104 }
2105
2106 //check layer 2
2107 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
2108
2109 if(layermap>-1 && layermap<map_count)
2110 {
2111 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
2112 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2113 if (combobuf[cmbcheck1].type == cBRIDGE)
2114 {
2115 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2116 {
2117 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2118 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2119 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2120 }
2121 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2122 }
2123 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2124 }
2125
2126 layermap=AbsoluteScr(map, scr+1)->layermap[1]-1;
2127
2128 if(layermap>-1 && layermap<map_count)
2129 {
2130 layerscreen=AbsoluteScr(map, scr+1)->layerscreen[1];
2131
2132 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2133 if (combobuf[cmbcheck2].type == cBRIDGE)
2134 {
2135 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2136 {
2137 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2138 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2139 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2140 }
2141 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2142 }
2143 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2144 }
2145
2146 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2147 {
2148 return true;
2149 }
2150
2151 break;
2152 }
2153 }
2154
2155 return false;
2156 }
2157
2158 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2159 {
2160 int32_t checkcombo;
2161
2162 if(alignment_arrow_timer>31)
2163 {
2164 if(scr<0)
2165 {
2166 scr=currscr;
2167 }
2168
2169 if((scr<128)) //do the misalignment arrows
2170 {
2171 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2172 {
2173 if(misaligned(currmap, scr, checkcombo, up))
2174 {
2175 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2176 }
2177 }
2178
2179 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2180 {
2181 if(misaligned(currmap, scr, checkcombo, down))
2182 {
2183 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2184 }
2185 }
2186
2187 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2188 {
2189 if(misaligned(currmap, scr, checkcombo, left))
2190 {
2191 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2192 }
2193 }
2194
2195 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2196 {
2197 if(misaligned(currmap, scr, checkcombo, right))
2198 {
2199 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2200 }
2201 }
2202
2203 int32_t tempalign;
2204
2205 //check top left corner
2206 checkcombo=0;
2207 tempalign=0;
2208 tempalign+=(misaligned(currmap, scr, checkcombo, up))?1:0;
2209 tempalign+=(misaligned(currmap, scr, checkcombo, left))?2:0;
2210
2211 switch(tempalign)
2212 {
2213 case 0:
2214 break;
2215
2216 case 1: //up
2217 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2218 break;
2219
2220 case 2: //left
2221 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2222 break;
2223
2224 case 3: //up-left
2225 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2226 break;
2227 }
2228
2229 //check top right corner
2230 checkcombo=15;
2231 tempalign=0;
2232 tempalign+=(misaligned(currmap, scr, checkcombo, up))?1:0;
2233 tempalign+=(misaligned(currmap, scr, checkcombo, right))?2:0;
2234
2235 switch(tempalign)
2236 {
2237 case 0:
2238 break;
2239
2240 case 1: //up
2241 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2242 break;
2243
2244 case 2: //right
2245 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2246 break;
2247
2248 case 3: //up-right
2249 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2250 break;
2251 }
2252
2253 //check bottom left corner
2254 checkcombo=160;
2255 tempalign=0;
2256 tempalign+=(misaligned(currmap, scr, checkcombo, down))?1:0;
2257 tempalign+=(misaligned(currmap, scr, checkcombo, left))?2:0;
2258
2259 switch(tempalign)
2260 {
2261 case 0:
2262 break;
2263
2264 case 1: //down
2265 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2266 break;
2267
2268 case 2: //left
2269 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2270 break;
2271
2272 case 3: //down-left
2273 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2274 break;
2275 }
2276
2277 //check bottom right corner
2278
2279 checkcombo=175;
2280 tempalign=0;
2281 tempalign+=(misaligned(currmap, scr, checkcombo, down))?1:0;
2282 tempalign+=(misaligned(currmap, scr, checkcombo, right))?2:0;
2283
2284 switch(tempalign)
2285 {
2286 case 0:
2287 break;
2288
2289 case 1: //down
2290 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2291 break;
2292
2293 case 2: //right
2294 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2295 break;
2296
2297 case 3: //down-right
2298 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2299 break;
2300 }
2301 }
2302 }
2303 }
2304
2305 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2306 {
2307 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2308 }
2309
2310 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2311 {
2312 if (map < 0 || screen < 0) return 0;
2313
2314 if(pos>175 || pos < 0)
2315 return 0;
2316
2317 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2318
2319 if(m->valid==0) return 0;
2320
2321 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2322
2323 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2324
2325 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2326
2327 if(scr->valid==0) return 0;
2328
2329 return scr->data[pos]; // entire combo code
2330 }
2331
2332 // Takes array index layer num., not actual layer num.
2333 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2334 {
2335 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2336
2337 if(map<0)
2338 map=currmap;
2339
2340 if(scr<0)
2341 scr=currscr;
2342
2343 mapscr *screen1;
2344
2345 if(prv_mode)
2346 {
2347 screen1=get_prvscr();
2348 }
2349 else
2350 {
2351 screen1=AbsoluteScr(currmap,currscr);
2352 }
2353
2354 int32_t layermap;
2355 layermap=screen1->layermap[lyr]-1;
2356
2357 if(layermap<0 || layermap >= map_count) return 0;
2358
2359 mapscr *layer;
2360
2361 if(prv_mode)
2362 layer = &prvlayers[lyr];
2363 else
2364 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2365
2366 int32_t combo = COMBOPOS(x,y);
2367
2368 if(combo>175 || combo < 0)
2369 return 0;
2370
2371 return layer->data[combo];
2372 }
2373
2374 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2375 {
2376 if(map<0)
2377 map=currmap;
2378
2379 if(scr<0)
2380 scr=currscr;
2381
2382 mapscr *screen1;
2383
2384 if(prv_mode)
2385 {
2386 screen1=get_prvscr();
2387 }
2388 else
2389 {
2390 screen1=AbsoluteScr(currmap,currscr);
2391 }
2392
2393 x = vbound(x, 0, 16*16);
2394 y = vbound(y, 0, 11*16);
2395 int32_t combo = COMBOPOS(x,y);
2396
2397 if(combo>175 || combo < 0)
2398 return 0;
2399
2400 return screen1->data[combo];
2401 }
2402
2403 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2404 {
2405 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2406 }
2407
2408 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2409 {
2410 if (map < 0 || screen < 0) return 0;
2411
2412 if(pos>175 || pos < 0)
2413 return 0;
2414
2415 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2416
2417 if(m->valid==0) return 0;
2418
2419 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2420
2421 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2422
2423 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2424
2425 if(scr->valid==0) return 0;
2426
2427 return scr->sflag[pos]; // entire combo code
2428 }
2429
2430 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2431 {
2432 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2433
2434 if(map<0)
2435 map=currmap;
2436
2437 if(scr<0)
2438 scr=currscr;
2439
2440 mapscr *screen1;
2441
2442 if(prv_mode)
2443 {
2444 screen1=get_prvscr();
2445 }
2446 else
2447 {
2448 screen1=AbsoluteScr(currmap,currscr);
2449 }
2450
2451 int32_t layermap;
2452 layermap=screen1->layermap[lyr]-1;
2453
2454 if(layermap<0 || layermap >= map_count) return 0;
2455
2456 mapscr *layer;
2457
2458 if(prv_mode)
2459 layer = &prvlayers[lyr];
2460 else
2461 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2462
2463 int32_t combo = COMBOPOS(x,y);
2464
2465 if(combo>175 || combo < 0)
2466 return 0;
2467
2468 return layer->sflag[combo];
2469 }
2470
2471 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2472 {
2473 if(map<0)
2474 map=currmap;
2475
2476 if(scr<0)
2477 scr=currscr;
2478
2479 mapscr *screen1;
2480
2481 if(prv_mode)
2482 {
2483 screen1=get_prvscr();
2484 }
2485 else
2486 {
2487 screen1=AbsoluteScr(currmap,currscr);
2488 }
2489
2490 x = vbound(x, 0, 16*16);
2491 y = vbound(y, 0, 11*16);
2492 int32_t combo = COMBOPOS(x,y);
2493
2494 if(combo>175 || combo < 0)
2495 return 0;
2496
2497 return screen1->sflag[combo];
2498 }
2499
2500 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2501 {
2502 mapscr *layers[7];
2503 mapscr *basescr;
2504 if(prv_mode)
2505 {
2506 layers[0] = &prvscr;
2507 basescr = layers[0];
2508 for(auto q = 1; q < 7; ++q)
2509 {
2510 if(prvlayers[q-1].valid)
2511 layers[q] = &(prvlayers[q-1]);
2512 else layers[q] = NULL;
2513 }
2514 }
2515 else
2516 {
2517 layers[0] = AbsoluteScr(currmap, currscr);
2518 basescr = layers[0];
2519 for(auto q = 1; q < 7; ++q)
2520 {
2521 int32_t lmap = basescr->layermap[q-1]-1;
2522 int32_t lscr = basescr->layerscreen[q-1];
2523 if(lmap < 0)
2524 layers[q] = NULL;
2525 else layers[q] = AbsoluteScr(lmap, lscr);
2526 }
2527 }
2528 for(auto q = 0; q < 7; ++q)
2529 {
2530 if(!layers[q]) continue;
2531 for(auto pos = 0; pos < 176; ++pos)
2532 {
2533 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2534 if(cmb.type == cTORCH)
2535 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2536 }
2537 }
2538 word maxffc = basescr->numFFC();
2539 for(auto q = 0; q < maxffc; ++q)
2540 {
2541 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2542 if(cmb.type == cTORCH)
2543 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2544 }
2545 }
2546
2547 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2548 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2549 {
2550 newcombo const& cmb = combobuf[cid];
2551 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2552 if(dither)
2553 {
2554 if (LayerDitherSz == 0)
2555 return;
2556 BITMAP* buf = create_bitmap_ex(8,16,16);
2557 clear_bitmap(buf);
2558 overcombo(buf,0,0,cid,cset);
2559 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2560 if(over)
2561 {
2562 if(transp)
2563 {
2564 color_map = &trans_table2;
2565 draw_trans_sprite(dest, buf, x, y);
2566 color_map = &trans_table;
2567 }
2568 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2569 }
2570 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2571 destroy_bitmap(buf);
2572 }
2573 else if(over)
2574 {
2575 if(transp)
2576 overcombotranslucent(dest,x,y,cid,cset,0);
2577 else overcombo(dest,x,y,cid,cset);
2578 }
2579 else put_combo(dest,x,y,cid,cset,flags,sflag);
2580 }
2581 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2582 {
2583 if(!md) return;
2584 for (int32_t i = 0; i < 176; i++)
2585 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2586 }
2587 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2588 {
2589 if(!md) return;
2590 for (int32_t i = 0; i < 176; i++)
2591 {
2592 int data = md->data[i];
2593 if(combo_class_buf[combobuf[data].type].overhead)
2594 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2595 }
2596 }
2597 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2598 {
2599 if(!LayerMaskInt[lyr])
2600 return nullptr;
2601 if(lyr == 0)
2602 return basescr;
2603 int layermap = basescr->layermap[lyr-1]-1;
2604
2605 if(layermap>-1 && layermap<map_count)
2606 {
2607 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2608 return &TheMaps[layerscreen];
2609 }
2610 return nullptr;
2611 }
2612 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t scr,int32_t hl_layer)
2613 {
2614 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2615 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2616
2617 if(map<0)
2618 map=currmap;
2619
2620 if(scr<0)
2621 scr=currscr;
2622
2623 mapscr *basescr;
2624 mapscr* layers[7] = {nullptr};
2625
2626 if(prv_mode)
2627 {
2628 hl_layer = -1;
2629 basescr=get_prvscr();
2630 }
2631 else
2632 {
2633 basescr=AbsoluteScr(map,scr);
2634 }
2635 layers[0] = _zmap_get_lyr_checked(0,basescr);
2636 for(int lyr = 1; lyr < 7; ++lyr)
2637 {
2638 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2639 : _zmap_get_lyr_checked(lyr,basescr);
2640 }
2641
2642 int32_t layermap, layerscreen;
2643 if(CurrentLayer < 1)
2644 layermap = -1;
2645 else
2646 {
2647 layermap=basescr->layermap[CurrentLayer-1]-1;
2648
2649 if(layermap<0)
2650 CurrentLayer=0;
2651 }
2652
2653 if(!(basescr->valid&mVALID))
2654 {
2655 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2656 rectfill(dest,x,y,x+255,y+175,vc(1));
2657
2658 if(ShowMisalignments)
2659 {
2660 check_alignments(dest,x,y,scr);
2661 }
2662
2663 return;
2664 }
2665
2666 if(LayerMaskInt[0]==0)
2667 {
2668 byte bgfill = 0;
2669 if (LayerDitherBG > -1)
2670 bgfill = vc(LayerDitherBG);
2671 rectfill(dest,x,y,x+255,y+175,bgfill);
2672 }
2673
2674 resize_mouse_pos=true;
2675 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2676 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2677
2678 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2679 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2680
2681 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2682
2683 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2684
2685 for(int32_t i=MAXFFCS-1; i>=0; i--)
2686 {
2687 if(basescr->ffcs[i].data)
2688 {
2689 if(!(basescr->ffcs[i].flags&ffc_changer))
2690 {
2691 if(!(basescr->ffcs[i].flags&ffc_overlay))
2692 {
2693 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2694 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2695
2696 if(basescr->ffcs[i].flags&ffc_trans)
2697 {
2698 overcomboblocktranslucent(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset,basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2699 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2700 }
2701 else
2702 {
2703 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2704 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2705 }
2706 }
2707 }
2708 }
2709 }
2710
2711 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2712 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2713
2714 int32_t doortype[4];
2715
2716 for(int32_t i=0; i<4; i++)
2717 {
2718 switch(basescr->door[i])
2719 {
2720 case dOPEN:
2721 doortype[i]=dt_pass;
2722 break;
2723
2724 case dLOCKED:
2725 doortype[i]=dt_lock;
2726 break;
2727
2728 case d1WAYSHUTTER:
2729 case dSHUTTER:
2730 doortype[i]=dt_shut;
2731 break;
2732
2733 case dBOSS:
2734 doortype[i]=dt_boss;
2735 break;
2736
2737 case dBOMB:
2738 doortype[i]=dt_bomb;
2739 break;
2740 }
2741 }
2742
2743 switch(basescr->door[up])
2744 {
2745 case dBOMB:
2746 over_door(dest,39,up,x,y,false, scr);
2747 [[fallthrough]];
2748 case dOPEN:
2749 case dLOCKED:
2750 case d1WAYSHUTTER:
2751 case dSHUTTER:
2752 case dBOSS:
2753 put_door(dest,7,up,doortype[up],x,y,false,scr);
2754 break;
2755
2756 case dWALK:
2757 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2758 {
2759 overcombo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2760 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[0],
2761 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[0]);
2762 }
2763 else
2764
2765 {
2766 put_combo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2767 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[0],
2768 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[0],0,0);
2769 }
2770
2771 break;
2772 }
2773
2774 switch(basescr->door[down])
2775 {
2776 case dBOMB:
2777 over_door(dest,135,down,x,y,false,scr);
2778 [[fallthrough]];
2779 case dOPEN:
2780 case dLOCKED:
2781 case d1WAYSHUTTER:
2782 case dSHUTTER:
2783 case dBOSS:
2784 put_door(dest,151,down,doortype[down],x,y,false,scr);
2785 break;
2786
2787 case dWALK:
2788 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2789 {
2790 overcombo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2791 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[1],
2792 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[1]);
2793 }
2794 else
2795 {
2796 put_combo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2797 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[1],
2798 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[1],0,0);
2799 }
2800
2801 break;
2802 }
2803
2804 switch(basescr->door[left])
2805 {
2806 case dBOMB:
2807 over_door(dest,66,left,x,y,false,scr);
2808 [[fallthrough]];
2809 case dOPEN:
2810 case dLOCKED:
2811 case d1WAYSHUTTER:
2812 case dSHUTTER:
2813 case dBOSS:
2814 put_door(dest,64,left,doortype[left],x,y,false,scr);
2815 break;
2816
2817 case dWALK:
2818 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2819 {
2820 overcombo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2821 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[2],
2822 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[2]);
2823 }
2824 else
2825 {
2826 put_combo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2827 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[2],
2828 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[2],0,0);
2829 }
2830
2831 break;
2832 }
2833
2834 switch(basescr->door[right])
2835 {
2836
2837 case dBOMB:
2838 over_door(dest,77,right,x,y,false,scr);
2839 [[fallthrough]];
2840 case dOPEN:
2841 case dLOCKED:
2842 case d1WAYSHUTTER:
2843 case dSHUTTER:
2844 case dBOSS:
2845 put_door(dest,78,right,doortype[right],x,y,false,scr);
2846 break;
2847
2848 case dWALK:
2849 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2850 {
2851 overcombo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2852 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[3],
2853 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[3]);
2854 }
2855 else
2856 {
2857 put_combo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2858 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[3],
2859 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[3],0,0);
2860 }
2861
2862 break;
2863 }
2864
2865 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2866 {
2867 frame=0;
2868 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2869 }
2870
2871 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2872 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2873 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2874
2875 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2876
2877 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2878 {
2879 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2880 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2881 }
2882 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2883
2884 for(int32_t i=MAXFFCS-1; i>=0; i--)
2885 {
2886 if(basescr->ffcs[i].data)
2887 {
2888 if(!(basescr->ffcs[i].flags&ffc_changer))
2889 {
2890 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2891 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2892
2893 if(basescr->ffcs[i].flags&ffc_overlay)
2894 {
2895 if(basescr->ffcs[i].flags&ffc_trans)
2896 {
2897 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2898 overcomboblocktranslucent(dest,tx,ty,basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2899 }
2900 else
2901 {
2902 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2903 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2904 }
2905 }
2906 }
2907 }
2908 }
2909
2910 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2911
2912 for(int32_t i=MAXFFCS-1; i>=0; i--)
2913 if(basescr->ffcs[i].data)
2914 if(basescr->ffcs[i].flags&ffc_changer)
2915 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2916
2917 if(flags&cWALK)
2918 {
2919 if(layers[0])
2920 for(int32_t i=0; i<176; i++)
2921 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2922
2923 for(int32_t k=0; k<2; k++)
2924 {
2925 if(layers[k+1])
2926 for(int32_t i=0; i<176; i++)
2927 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2928 }
2929 for(int32_t i=MAXFFCS-1; i>=0; i--)
2930 {
2931 if(auto data = basescr->ffcs[i].data)
2932 {
2933 if(!(basescr->ffcs[i].flags&ffc_changer))
2934 {
2935 newcombo const& cmb = combobuf[data];
2936 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2937 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2938
2939 if(basescr->ffcs[i].flags&ffc_solid)
2940 {
2941 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
2942 }
2943
2944 if(cmb.type == cSLOPE)
2945 {
2946 slope_info s(cmb, tx, ty);
2947 s.draw(dest, 0, 0, COLOR_SLOPE);
2948 }
2949 }
2950 }
2951 }
2952 }
2953
2954 if(flags&cFLAGS)
2955 {
2956 if(LayerMaskInt[CurrentLayer]!=0)
2957 {
2958 for(int32_t i=0; i<176; i++)
2959 {
2960 if(CurrentLayer==0)
2961 {
2962 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
2963 }
2964 else
2965 {
2966 if(prv_mode)
2967 {
2968 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
2969 }
2970 else
2971 {
2972 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
2973
2974 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
2975 {
2976 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
2977 TheMaps[_lscr].data[i],
2978 TheMaps[_lscr].cset[i], flags,
2979 TheMaps[_lscr].sflag[i]);
2980 }
2981 }
2982 }
2983 }
2984 }
2985 }
2986
2987 int32_t dark = basescr->flags&cDARK;
2988
2989 if(dark && !(flags&cNODARK)
2990 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
2991 {
2992 for(int32_t j=0; j<80; j++)
2993 {
2994 for(int32_t i=0; i<(80)-j; i++)
2995 {
2996 if(((i^j)&1)==0)
2997 {
2998 putpixel(dest,x+i,y+j,vc(blackout_color));
2999 }
3000 }
3001 }
3002 }
3003
3004 if(ShowMisalignments)
3005 {
3006 check_alignments(dest,x,y,scr);
3007 }
3008
3009 resize_mouse_pos=false;
3010 }
3011
3012 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3013 {
3014 if(map<0)
3015 map=currmap;
3016
3017 if(scr<0)
3018 scr=currscr;
3019
3020 mapscr* layer=AbsoluteScr(map,scr);
3021 int32_t layermap=0, layerscreen=0;
3022
3023 if(!(layer->valid&mVALID))
3024 {
3025 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3026 rectfill(dest,x,y,x+255,y+15,vc(1));
3027 return;
3028 }
3029
3030 int32_t dark = layer->flags&4;
3031
3032 resize_mouse_pos=true;
3033
3034 if(LayerMaskInt[0]==0)
3035 {
3036 rectfill(dest,x,y,x+255,y+15,0);
3037 }
3038
3039
3040 for(int32_t k=1; k<3; k++)
3041 {
3042 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3043 {
3044 layermap=layer->layermap[k]-1;
3045
3046 if(layermap>-1 && layermap<map_count)
3047 {
3048 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3049
3050 for(int32_t i=c; i<(c&0xF0)+16; i++)
3051 {
3052 auto data = TheMaps[layerscreen].data[i];
3053 auto cs = TheMaps[layerscreen].cset[i];
3054 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3055 }
3056 }
3057 }
3058 }
3059
3060 if(LayerMaskInt[0]!=0)
3061 {
3062 for(int32_t i=c; i<(c&0xF0)+16; i++)
3063 {
3064 word cmbdat = (i < 176 ? layer->data[i] : 0);
3065 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3066 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3067 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3068 cmbflag,(layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3069 }
3070 }
3071
3072 for(int32_t k=0; k<2; k++)
3073 {
3074 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3075 {
3076 layermap=layer->layermap[k]-1;
3077
3078 if(layermap>-1 && layermap<map_count)
3079 {
3080 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3081
3082 for(int32_t i=c; i<(c&0xF0)+16; i++)
3083 {
3084 auto data = TheMaps[layerscreen].data[i];
3085 auto cs = TheMaps[layerscreen].cset[i];
3086 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3087 }
3088 }
3089 }
3090 }
3091
3092 int32_t doortype[4];
3093
3094 for(int32_t i=0; i<4; i++)
3095 {
3096 switch(layer->door[i])
3097 {
3098 case dOPEN:
3099 doortype[i]=dt_pass;
3100 break;
3101
3102 case dLOCKED:
3103 doortype[i]=dt_lock;
3104 break;
3105
3106 case d1WAYSHUTTER:
3107 case dSHUTTER:
3108 doortype[i]=dt_shut;
3109 break;
3110
3111 case dBOSS:
3112 doortype[i]=dt_boss;
3113 break;
3114
3115 case dBOMB:
3116 doortype[i]=dt_bomb;
3117 break;
3118 }
3119 }
3120
3121 if(c<16)
3122 {
3123 switch(layer->door[up])
3124 {
3125 case dBOMB:
3126 case dOPEN:
3127 case dLOCKED:
3128 case d1WAYSHUTTER:
3129 case dSHUTTER:
3130 case dBOSS:
3131 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3132 break;
3133 }
3134 }
3135 else if(c>159)
3136 {
3137 switch(layer->door[down])
3138 {
3139 case dBOMB:
3140 case dOPEN:
3141 case dLOCKED:
3142 case d1WAYSHUTTER:
3143 case dSHUTTER:
3144 case dBOSS:
3145 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3146 break;
3147 }
3148 }
3149
3150 for(int32_t k=2; k<4; k++)
3151 {
3152 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3153 {
3154 layermap=layer->layermap[k]-1;
3155
3156 if(layermap>-1 && layermap<map_count)
3157 {
3158 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3159
3160 for(int32_t i=c; i<(c&0xF0)+16; i++)
3161 {
3162 if(layer->layeropacity[k]<255)
3163 {
3164 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3165 }
3166 else
3167 {
3168 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3169 }
3170 }
3171 }
3172 }
3173 }
3174
3175 //Overhead L0
3176 if(LayerMaskInt[0]!=0)
3177 {
3178 for(int32_t i=c; i<(c&0xF0)+16; i++)
3179 {
3180 int32_t ct1=layer->data[i];
3181 int32_t ct3=combobuf[ct1].type;
3182
3183 if(combo_class_buf[ct3].overhead)
3184 {
3185 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3186 }
3187 }
3188 }
3189
3190 //Overhead L1/2
3191 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3192 {
3193 for(int32_t k = 0; k < 2; ++k)
3194 {
3195 if(LayerMaskInt[k+1]!=0)
3196 {
3197 layermap=layer->layermap[k]-1;
3198
3199 if(layermap>-1 && layermap<map_count)
3200 {
3201 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3202 for(int32_t i=c; i<(c&0xF0)+16; i++)
3203 {
3204 auto data = TheMaps[layerscreen].data[i];
3205 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3206 auto cs = TheMaps[layerscreen].cset[i];
3207 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3208 }
3209 }
3210 }
3211 }
3212 }
3213
3214 for(int32_t k=4; k<6; k++)
3215 {
3216 if(LayerMaskInt[k+1]!=0)
3217 {
3218 layermap=layer->layermap[k]-1;
3219
3220 if(layermap>-1 && layermap<map_count)
3221 {
3222 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3223
3224 for(int32_t i=c; i<(c&0xF0)+16; i++)
3225 {
3226 auto data = TheMaps[layerscreen].data[i];
3227 auto cs = TheMaps[layerscreen].cset[i];
3228 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3229 }
3230 }
3231 }
3232 }
3233
3234 if(flags&cWALK)
3235 {
3236 if(LayerMaskInt[0]!=0)
3237 {
3238 for(int32_t i=c; i<(c&0xF0)+16; i++)
3239 {
3240 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3241 }
3242 }
3243
3244 for(int32_t k=0; k<2; k++)
3245 {
3246 if(LayerMaskInt[k+1]!=0)
3247 {
3248 for(int32_t i=c; i<(c&0xF0)+16; i++)
3249 {
3250 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3251 }
3252 }
3253 }
3254 }
3255
3256 if(flags&cFLAGS)
3257 {
3258 if(LayerMaskInt[CurrentLayer]!=0)
3259 {
3260 for(int32_t i=c; i<(c&0xF0)+16; i++)
3261 {
3262 if(CurrentLayer==0)
3263 {
3264 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3265 }
3266 else
3267 {
3268 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3269
3270 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3271 {
3272 if(i < 176)
3273 {
3274 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3275 TheMaps[_lscr].data[i],
3276 TheMaps[_lscr].cset[i], flags|dark,
3277 TheMaps[_lscr].sflag[i]);
3278 }
3279 else
3280 {
3281 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3282 }
3283 }
3284 }
3285 }
3286 }
3287
3288 /*
3289 if (LayerMaskInt[0]!=0) {
3290 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3291 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3292 }
3293 }
3294 */
3295 }
3296
3297 if(ShowMisalignments)
3298 {
3299 if(c<16)
3300 {
3301 check_alignments(dest,x,y,scr);
3302 }
3303 else if(c>159)
3304 {
3305 check_alignments(dest,x,y-160,scr);
3306 }
3307 }
3308
3309 resize_mouse_pos=false;
3310
3311 }
3312
3313 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3314 {
3315 if(map<0)
3316 map=currmap;
3317
3318 if(scr<0)
3319 scr=currscr;
3320
3321 mapscr* layer=AbsoluteScr(map,scr);
3322 int32_t layermap=0, layerscreen=0;
3323
3324 if(!(layer->valid&mVALID))
3325 {
3326 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3327 rectfill(dest,x,y,x+15,y+175,vc(1));
3328 return;
3329 }
3330
3331 int32_t dark = layer->flags&4;
3332
3333 resize_mouse_pos=true;
3334
3335
3336 if(LayerMaskInt[0]==0)
3337 {
3338 rectfill(dest,x,y,x+15,y+175,0);
3339 }
3340
3341
3342 for(int32_t k=1; k<3; k++)
3343 {
3344 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3345 {
3346 layermap=layer->layermap[k]-1;
3347
3348 if(layermap>-1 && layermap<map_count)
3349 {
3350 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3351
3352 for(int32_t i=c; i<176; i+=16)
3353 {
3354 auto data = TheMaps[layerscreen].data[i];
3355 auto cs = TheMaps[layerscreen].cset[i];
3356 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3357 }
3358 }
3359 }
3360 }
3361
3362 if(LayerMaskInt[0]!=0)
3363 {
3364 for(int32_t i=c; i<176; i+=16)
3365 {
3366 word cmbdat = layer->data[i];
3367 byte cmbcset = layer->cset[i];
3368 int32_t cmbflag = layer->sflag[i];
3369 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3370 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3371 }
3372 }
3373
3374 for(int32_t k=0; k<2; k++)
3375 {
3376 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3377 {
3378 layermap=layer->layermap[k]-1;
3379
3380 if(layermap>-1 && layermap<map_count)
3381 {
3382 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3383
3384 for(int32_t i=c; i<176; i+=16)
3385 {
3386 auto data = TheMaps[layerscreen].data[i];
3387 auto cs = TheMaps[layerscreen].cset[i];
3388 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3389 }
3390 }
3391 }
3392 }
3393
3394 int32_t doortype[4];
3395
3396 for(int32_t i=0; i<4; i++)
3397 {
3398 switch(layer->door[i])
3399 {
3400 case dOPEN:
3401 doortype[i]=dt_pass;
3402 break;
3403
3404 case dLOCKED:
3405 doortype[i]=dt_lock;
3406 break;
3407
3408 case d1WAYSHUTTER:
3409 case dSHUTTER:
3410 doortype[i]=dt_shut;
3411 break;
3412
3413 case dBOSS:
3414 doortype[i]=dt_boss;
3415 break;
3416
3417 case dBOMB:
3418 doortype[i]=dt_bomb;
3419 break;
3420 }
3421 }
3422
3423 if((c&0x0F)==0)
3424 {
3425 switch(layer->door[left])
3426 {
3427
3428 case dBOMB:
3429 case dOPEN:
3430 case dLOCKED:
3431 case d1WAYSHUTTER:
3432 case dSHUTTER:
3433 case dBOSS:
3434 // put_door(dest,64,left,doortype[left],x+256,y,true);
3435 put_door(dest,64,left,doortype[left],x,y,true,scr);
3436 break;
3437 }
3438 }
3439 else if((c&0x0F)==15)
3440 {
3441 switch(layer->door[right])
3442 {
3443 case dBOMB:
3444 case dOPEN:
3445 case dLOCKED:
3446 case d1WAYSHUTTER:
3447 case dSHUTTER:
3448 case dBOSS:
3449 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3450 break;
3451 }
3452 }
3453
3454 for(int32_t k=2; k<4; k++)
3455 {
3456 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3457 {
3458 layermap=layer->layermap[k]-1;
3459
3460 if(layermap>-1 && layermap<map_count)
3461 {
3462 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3463
3464 for(int32_t i=c; i<176; i+=16)
3465 {
3466 auto data = TheMaps[layerscreen].data[i];
3467 auto cs = TheMaps[layerscreen].cset[i];
3468 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3469 }
3470 }
3471 }
3472 }
3473
3474 //Overhead L0
3475 if(LayerMaskInt[0]!=0)
3476 {
3477 for(int32_t i=c; i<176; i+=16)
3478 {
3479 auto data = TheMaps[layerscreen].data[i];
3480 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3481 auto cs = TheMaps[layerscreen].cset[i];
3482 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3483 }
3484 }
3485 //Overhead L1/2
3486 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3487 {
3488 for(int32_t k = 0; k < 2; ++k)
3489 {
3490 if(LayerMaskInt[k+1]!=0)
3491 {
3492 layermap=layer->layermap[k]-1;
3493
3494 if(layermap>-1 && layermap<map_count)
3495 {
3496 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3497 for(int32_t i=c; i<176; i+=16)
3498 {
3499 auto data = TheMaps[layerscreen].data[i];
3500 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3501 auto cs = TheMaps[layerscreen].cset[i];
3502 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3503 }
3504 }
3505 }
3506 }
3507 }
3508
3509
3510 for(int32_t k=4; k<6; k++)
3511 {
3512 if(LayerMaskInt[k+1]!=0)
3513 {
3514 layermap=layer->layermap[k]-1;
3515
3516 if(layermap>-1 && layermap<map_count)
3517 {
3518 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3519
3520 for(int32_t i=c; i<176; i+=16)
3521 {
3522 auto data = TheMaps[layerscreen].data[i];
3523 auto cs = TheMaps[layerscreen].cset[i];
3524 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3525 }
3526 }
3527 }
3528 }
3529
3530 if(flags&cWALK)
3531 {
3532 if(LayerMaskInt[0]!=0)
3533 {
3534 for(int32_t i=c&0xF; i<176; i+=16)
3535 {
3536 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3537 }
3538 }
3539
3540 for(int32_t k=0; k<2; k++)
3541 {
3542 if(LayerMaskInt[k+1]!=0)
3543 {
3544 for(int32_t i=c&0xF; i<176; i+=16)
3545 {
3546 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3547 }
3548 }
3549 }
3550 }
3551
3552 if(flags&cFLAGS)
3553 {
3554 if(LayerMaskInt[CurrentLayer]!=0)
3555 {
3556 for(int32_t i=c; i<176; i+=16)
3557 {
3558 if(CurrentLayer==0)
3559 {
3560 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3561 }
3562 else
3563 {
3564 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3565
3566 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3567 {
3568 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3569 TheMaps[_lscr].data[i],
3570 TheMaps[_lscr].cset[i], flags|dark,
3571 TheMaps[_lscr].sflag[i]);
3572 }
3573 }
3574 }
3575 }
3576 }
3577
3578 if(ShowMisalignments)
3579 {
3580 if((c&0x0F)==0)
3581 {
3582 check_alignments(dest,x,y,scr);
3583 }
3584 else if((c&0x0F)==15)
3585 {
3586 check_alignments(dest,x-240,y,scr);
3587 }
3588 }
3589
3590 resize_mouse_pos=false;
3591 }
3592
3593 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3594 {
3595 if(map<0)
3596 map=currmap;
3597
3598 if(scr<0)
3599 scr=currscr;
3600
3601 mapscr* layer=AbsoluteScr(map,scr);
3602 int32_t layermap=0, layerscreen=0;
3603
3604 if(!(layer->valid&mVALID))
3605 {
3606 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3607 rectfill(dest,x,y,x+15,y+15,vc(1));
3608 return;
3609 }
3610
3611 int32_t dark = layer->flags&4;
3612
3613 resize_mouse_pos=true;
3614
3615 if(LayerMaskInt[0]!=0)
3616 {
3617 rectfill(dest,x,y,x+15,y+15,0);
3618 }
3619
3620 for(int32_t k=1; k<3; k++)
3621 {
3622 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3623 {
3624 layermap=layer->layermap[k]-1;
3625
3626 if(layermap>-1 && layermap<map_count)
3627 {
3628 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3629
3630 auto data = TheMaps[layerscreen].data[c];
3631 auto cs = TheMaps[layerscreen].cset[c];
3632 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3633 }
3634 }
3635 }
3636
3637 if(LayerMaskInt[0]!=0)
3638 {
3639 word cmbdat = layer->data[c];
3640 byte cmbcset = layer->cset[c];
3641 int32_t cmbflag = layer->sflag[c];
3642 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3643 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3644 }
3645
3646
3647 for(int32_t k=0; k<2; k++)
3648 {
3649 if(LayerMaskInt[k+1]!=0)
3650 {
3651 layermap=layer->layermap[k]-1;
3652
3653 if(layermap>-1 && layermap<map_count)
3654 {
3655 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3656
3657 auto data = TheMaps[layerscreen].data[c];
3658 auto cs = TheMaps[layerscreen].cset[c];
3659 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3660 }
3661 }
3662 }
3663
3664 for(int32_t k=2; k<4; k++)
3665 {
3666 if(LayerMaskInt[k+1]!=0)
3667 {
3668 layermap=layer->layermap[k]-1;
3669
3670 if(layermap>-1 && layermap<map_count)
3671 {
3672 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3673 auto data = TheMaps[layerscreen].data[c];
3674 auto cs = TheMaps[layerscreen].cset[c];
3675 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3676 }
3677 }
3678 }
3679
3680 //Overhead L0
3681 if(LayerMaskInt[0]!=0)
3682 {
3683 auto data = TheMaps[layerscreen].data[c];
3684 if(combo_class_buf[combobuf[data].type].overhead)
3685 {
3686 auto cs = TheMaps[layerscreen].cset[c];
3687 drawcombo(dest,x,y,data,cs,0,0);
3688 }
3689 }
3690 //Overhead L1/2
3691 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3692 {
3693 for(int32_t k = 0; k < 2; ++k)
3694 {
3695 if(LayerMaskInt[k+1]!=0)
3696 {
3697 layermap=layer->layermap[k]-1;
3698
3699 if(layermap>-1 && layermap<map_count)
3700 {
3701 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3702 auto data = TheMaps[layerscreen].data[c];
3703 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3704 auto cs = TheMaps[layerscreen].cset[c];
3705 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3706 }
3707 }
3708 }
3709 }
3710
3711
3712 for(int32_t k=4; k<6; k++)
3713 {
3714 if(LayerMaskInt[k+1]!=0)
3715 {
3716 layermap=layer->layermap[k]-1;
3717
3718 if(layermap>-1 && layermap<map_count)
3719 {
3720 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3721 auto data = TheMaps[layerscreen].data[c];
3722 auto cs = TheMaps[layerscreen].cset[c];
3723 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3724 }
3725 }
3726 }
3727
3728 if(flags&cWALK)
3729 {
3730 if(LayerMaskInt[0]!=0)
3731 {
3732 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3733 }
3734
3735 for(int32_t k=0; k<2; k++)
3736 {
3737 if(LayerMaskInt[k+1]!=0)
3738 {
3739 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3740 }
3741 }
3742 }
3743
3744 if(flags&cFLAGS)
3745 {
3746 if(LayerMaskInt[CurrentLayer]!=0)
3747 {
3748 int32_t i = c;
3749 //for(int32_t i=c; i==c; i++)
3750 {
3751 if(CurrentLayer==0)
3752 {
3753 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3754 }
3755 else
3756 {
3757 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3758
3759 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3760 {
3761 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3762 TheMaps[_lscr].data[i],
3763 TheMaps[_lscr].cset[i], flags|dark,
3764 TheMaps[_lscr].sflag[i]);
3765 }
3766 }
3767 }
3768 }
3769 }
3770
3771 if(ShowMisalignments)
3772 {
3773 switch(c)
3774 {
3775 case 0:
3776 check_alignments(dest,x,y,scr);
3777 break;
3778
3779 case 15:
3780 check_alignments(dest,x-240,y,scr);
3781 break;
3782
3783 case 160:
3784 check_alignments(dest,x,y-160,scr);
3785 break;
3786
3787 case 175:
3788 check_alignments(dest,x-240,y-160,scr);
3789 break;
3790 }
3791 }
3792
3793 resize_mouse_pos=false;
3794
3795 }
3796
3797 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3798 {
3799 if (InvalidBG == 2)
3800 {
3801 draw_checkerboard(dest, x, y, 16);
3802 }
3803 else if(InvalidBG == 1)
3804 {
3805 for(int32_t dy=0; dy<16; dy++)
3806 {
3807 for(int32_t dx=0; dx<16; dx++)
3808 {
3809 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3810 }
3811 }
3812 }
3813 else
3814 {
3815 rectfill(dest, x, y, x+15, y+15, vc(0));
3816 rect(dest, x, y, x+15, y+15, vc(15));
3817 line(dest, x, y, x+15, y+15, vc(15));
3818 line(dest, x, y+15, x+15, y, vc(15));
3819 }
3820 }
3821
3822 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3823 {
3824 if (InvalidBG == 2)
3825 {
3826 for(int32_t q = 0; q < 11; ++q)
3827 draw_checkerboard(dest, x, y + q * 16, 16);
3828 }
3829 else if(InvalidBG == 1)
3830 {
3831 for(int32_t dy=0; dy<176; dy++)
3832 {
3833 for(int32_t dx=0; dx<16; dx++)
3834 {
3835 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3836 }
3837 }
3838 }
3839 else
3840 {
3841 rectfill(dest, x, y, x+15, y+175, vc(0));
3842 rect(dest, x, y, x+15, y+175, vc(15));
3843 line(dest, x, y, x+15, y+175, vc(15));
3844 line(dest, x, y+175, x+15, y, vc(15));
3845 }
3846 }
3847
3848 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3849 {
3850 if (InvalidBG == 2)
3851 {
3852 for (int32_t q = 0; q < 16; ++q)
3853 draw_checkerboard(dest, x + q * 16, y, 16);
3854 }
3855 else if(InvalidBG == 1)
3856 {
3857 for(int32_t dy=0; dy<16; dy++)
3858 {
3859 for(int32_t dx=0; dx<256; dx++)
3860 {
3861 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3862 }
3863 }
3864 }
3865 else
3866 {
3867 rectfill(dest, x, y, x+255, y+15, vc(0));
3868 rect(dest, x, y, x+255, y+15, vc(15));
3869 line(dest, x, y, x+255, y+15, vc(15));
3870 line(dest, x, y+15, x+255, y, vc(15));
3871 }
3872 }
3873
3874 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3875 {
3876 for(int32_t i=0; i<176; i++)
3877 {
3878 word cmbdat = screens[TEMPLATE].data[i];
3879 byte cmbcset = screens[TEMPLATE].cset[i];
3880 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3881 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3882 }
3883 }
3884
3885 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3886 {
3887 for(int32_t i=0; i<176; i++)
3888 {
3889 word cmbdat = screens[TEMPLATE2].data[i];
3890 byte cmbcset = screens[TEMPLATE2].cset[i];
3891 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3892 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3893 }
3894 }
3895
3896 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3897 {
3898 word cmbdat = screens[TEMPLATE].data[pos];
3899 byte cmbcset = screens[TEMPLATE].cset[pos];
3900 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3901 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3902 }
3903
3904 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3905 {
3906 word cmbdat = screens[currscr].secretcombo[scombo];
3907 byte cmbcset = screens[currscr].secretcset[scombo];
3908 byte cmbflag = screens[currscr].secretflag[scombo];
3909 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3910 }
3911
3912 void zmap::scroll(int32_t dir, bool warp)
3913 {
3914 if(currmap<map_count)
3915 {
3916 switch(dir)
3917 {
3918 case up:
3919 if(warp && Map.CurrScr()->flags2&wfUP)
3920 {
3921 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3922 }
3923 else if(currscr>15)
3924 {
3925 setCurrScr(currscr-16);
3926 }
3927
3928 break;
3929
3930 case down:
3931 if(warp && Map.CurrScr()->flags2&wfDOWN)
3932 {
3933 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3934 }
3935 else if(currscr<MAPSCRS-16)
3936 {
3937 setCurrScr(currscr+16);
3938 }
3939
3940 break;
3941
3942 case left:
3943 if(warp && Map.CurrScr()->flags2&wfLEFT)
3944 {
3945 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3946 }
3947 else if(currscr&15)
3948 {
3949 setCurrScr(currscr-1);
3950 }
3951
3952 break;
3953
3954 case right:
3955 if(warp && Map.CurrScr()->flags2&wfRIGHT)
3956 {
3957 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
3958 }
3959 else if((currscr&15)<15 && currscr<MAPSCRS-1)
3960 {
3961 setCurrScr(currscr+1);
3962 }
3963
3964 break;
3965 }
3966 }
3967 }
3968
3969 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
3970 {
3971 switch(side)
3972 {
3973 case up:
3974 switch(door)
3975 {
3976 case dWALL:
3977 case dBOMB:
3978 case dWALK:
3979 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
3980 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
3981 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
3982 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
3983 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
3984 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
3985 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
3986 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
3987 break;
3988
3989 default:
3990 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
3991 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
3992 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
3993 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
3994 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
3995 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
3996 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
3997 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
3998 break;
3999 }
4000
4001 break;
4002
4003 case down:
4004 switch(door)
4005 {
4006 case dWALL:
4007 case dBOMB:
4008 case dWALK:
4009 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
4010 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
4011 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
4012 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
4013 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
4014 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
4015 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
4016 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
4017 break;
4018
4019 default:
4020 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
4021 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
4022 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
4023 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
4024 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
4025 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
4026 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
4027 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
4028 break;
4029 }
4030
4031 break;
4032
4033 case left:
4034 switch(door)
4035 {
4036 case dWALL:
4037 case dBOMB:
4038 case dWALK:
4039 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
4040 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
4041 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
4042 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
4043 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
4044 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4045 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4046 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4047 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4048 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4049 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4050 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4051 break;
4052
4053 default:
4054 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4055 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4056 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4057 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4058 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4059 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4060 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4061 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4062 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4063 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4064 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4065 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4066 break;
4067 }
4068
4069 break;
4070
4071 case right:
4072 switch(door)
4073 {
4074 case dWALL:
4075 case dBOMB:
4076 case dWALK:
4077 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4078 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4079 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4080 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4081 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4082 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4083 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4084 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4085 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4086 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4087 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4088 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4089 break;
4090
4091 default:
4092 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4093 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4094 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4095 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4096 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4097 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4098 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4099 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4100 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4101 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4102 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4103 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4104 break;
4105 }
4106
4107 break;
4108 }
4109 }
4110 void zmap::DoPutDoorCommand(int side, int door, bool force)
4111 {
4112 if(!force && screens[currscr].door[side] == door)
4113 return;
4114 bool already_list = InListCommand();
4115 if(!already_list)
4116 StartListCommand();
4117 DoSetDoorCommand(currscr,side,door);
4118 if(door != dNONE)
4119 {
4120 word data[176] = {0};
4121 byte cset[176] = {0};
4122 fetch_door(side, door, screens[currscr].door_combo_set, data, cset);
4123 for(int q = 0; q < 176; ++q)
4124 if(data[q])
4125 DoSetComboCommand(currmap,currscr,q,data[q],cset[q]);
4126 }
4127 if(!already_list)
4128 FinishListCommand();
4129 }
4130 void zmap::putdoor(int32_t scr,int32_t side,int32_t door)
4131 {
4132 if(screens[scr].door[side] == door)
4133 return;
4134 screens[scr].door[side] = door;
4135 if(door != dNONE)
4136 {
4137 word data[176] = {0};
4138 byte cset[176] = {0};
4139 fetch_door(side, door, screens[scr].door_combo_set, data, cset);
4140 for(int q = 0; q < 176; ++q)
4141 if(data[q])
4142 {
4143 screens[scr].data[q] = data[q];
4144 screens[scr].cset[q] = cset[q];
4145 }
4146 }
4147 }
4148
4149 void list_command::execute()
4150 {
4151 for (auto command : commands)
4152 {
4153 command->execute();
4154 }
4155 }
4156
4157 void list_command::undo()
4158 {
4159 for (int i = commands.size() - 1; i >= 0; i--)
4160 {
4161 commands[i]->undo();
4162 }
4163 }
4164
4165 int list_command::size()
4166 {
4167 int s = 0;
4168 for (auto command : commands)
4169 {
4170 s += command->size();
4171 }
4172 return s;
4173 }
4174
4175 void set_combo_command::execute()
4176 {
4177 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4178 if(!mapscr_ptr) return;
4179
4180 mapscr_ptr->valid |= mVALID;
4181 if (combo != -1) mapscr_ptr->data[pos] = combo;
4182 mapscr_ptr->cset[pos] = cset;
4183 }
4184
4185 void set_combo_command::undo()
4186 {
4187 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4188 if(!mapscr_ptr) return;
4189 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4190 mapscr_ptr->cset[pos] = prev_cset;
4191 }
4192
4193 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4194 {
4195 std::array<int, 2> inita_arr;
4196 std::copy(std::begin(ffc.inita), std::end(ffc.inita), inita_arr.begin());
4197 std::array<int, 8> initd_arr;
4198 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4199
4200 return {
4201 .x = ffc.x,
4202 .y = ffc.y,
4203 .vx = ffc.vx,
4204 .vy = ffc.vy,
4205 .ax = ffc.ax,
4206 .ay = ffc.ay,
4207 .data = ffc.data,
4208 .cset = ffc.cset,
4209 .delay = ffc.delay,
4210 .link = ffc.link,
4211 .script = ffc.script,
4212 .tw = ffc.txsz,
4213 .th = ffc.tysz,
4214 .ew = ffc.hit_width,
4215 .eh = ffc.hit_height,
4216 .flags = ffc.flags,
4217 .inita = inita_arr,
4218 .initd = initd_arr,
4219 };
4220 }
4221
4222 void set_ffc_command::execute()
4223 {
4224 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4225 if(!mapscr_ptr) return;
4226
4227 mapscr_ptr->valid |= mVALID;
4228 mapscr_ptr->ffcs[i].x = data.x;
4229 mapscr_ptr->ffcs[i].y = data.y;
4230 mapscr_ptr->ffcs[i].vx = data.vx;
4231 mapscr_ptr->ffcs[i].vy = data.vy;
4232 mapscr_ptr->ffcs[i].ax = data.ax;
4233 mapscr_ptr->ffcs[i].ay = data.ay;
4234 mapscr_ptr->ffcs[i].data = data.data;
4235 mapscr_ptr->ffcs[i].cset = data.cset;
4236 mapscr_ptr->ffcs[i].delay = data.delay;
4237 mapscr_ptr->ffcs[i].link = data.link;
4238 mapscr_ptr->ffcs[i].script = data.script;
4239 mapscr_ptr->ffcs[i].flags = data.flags;
4240 mapscr_ptr->ffEffectWidth(i, data.ew);
4241 mapscr_ptr->ffEffectHeight(i, data.eh);
4242 mapscr_ptr->ffTileWidth(i, data.tw);
4243 mapscr_ptr->ffTileHeight(i, data.th);
4244 std::copy(std::begin(data.inita), std::end(data.inita), std::begin(mapscr_ptr->ffcs[i].inita));
4245 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4246 mapscr_ptr->ffcCountMarkDirty();
4247 mapscr_ptr->ffcs[i].updateSolid();
4248 }
4249
4250 void set_ffc_command::undo()
4251 {
4252 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4253 if(!mapscr_ptr) return;
4254
4255 mapscr_ptr->ffcs[i].x = prev_data.x;
4256 mapscr_ptr->ffcs[i].y = prev_data.y;
4257 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4258 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4259 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4260 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4261 mapscr_ptr->ffcs[i].data = prev_data.data;
4262 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4263 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4264 mapscr_ptr->ffcs[i].link = prev_data.link;
4265 mapscr_ptr->ffcs[i].script = prev_data.script;
4266 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4267 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4268 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4269 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4270 mapscr_ptr->ffTileHeight(i, prev_data.th);
4271 std::copy(std::begin(prev_data.inita), std::end(prev_data.inita), std::begin(mapscr_ptr->ffcs[i].inita));
4272 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4273 mapscr_ptr->ffcCountMarkDirty();
4274 mapscr_ptr->ffcs[i].updateSolid();
4275 }
4276
4277 void set_flag_command::execute()
4278 {
4279 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4280 if(!mapscr_ptr) return;
4281
4282 mapscr_ptr->valid |= mVALID;
4283 mapscr_ptr->sflag[pos] = flag;
4284 }
4285
4286 void set_flag_command::undo()
4287 {
4288 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4289 if(!mapscr_ptr) return;
4290 mapscr_ptr->sflag[pos] = prev_flag;
4291 }
4292
4293 void set_door_command::execute()
4294 {
4295 auto* mapscr_ptr = Map.AbsoluteScr(view_map, view_scr);
4296 if(!mapscr_ptr) return;
4297
4298 mapscr_ptr->valid |= mVALID;
4299 mapscr_ptr->door[side] = door;
4300 }
4301
4302 void set_door_command::undo()
4303 {
4304 Map.AbsoluteScr(view_map, view_scr)->door[side] = prev_door;
4305 }
4306
4307 void set_dcs_command::execute()
4308 {
4309 auto* mapscr_ptr = Map.AbsoluteScr(view_map, view_scr);
4310 if(!mapscr_ptr) return;
4311
4312 mapscr_ptr->valid |= mVALID;
4313 mapscr_ptr->door_combo_set = dcs;
4314 }
4315
4316 void set_dcs_command::undo()
4317 {
4318 Map.AbsoluteScr(view_map, view_scr)->door_combo_set = prev_dcs;
4319 }
4320
4321 void paste_screen_command::execute()
4322 {
4323 perform(screen.get());
4324 }
4325
4326 void paste_screen_command::undo()
4327 {
4328 if (prev_screens.size() > 1)
4329 {
4330 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4331 ASSERT(prev_screens.size() == 128);
4332 for (int i = 0; i < 128; i++)
4333 {
4334 copy_mapscr(Map.AbsoluteScr(view_map, i), prev_screens[i].get());
4335 // TODO: why not just this?
4336 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4337 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4338 }
4339 return;
4340 }
4341
4342 perform(prev_screens[0].get());
4343 }
4344
4345 int paste_screen_command::size()
4346 {
4347 return prev_screens.size() + 1;
4348 }
4349
4350 void paste_screen_command::perform(mapscr* to)
4351 {
4352 if (to)
4353 {
4354 switch (type) {
4355 case ScreenAll: Map.PasteAll(*to); break;
4356 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4357 case ScreenData: Map.PasteScreenData(*to); break;
4358 case ScreenDoors: Map.PasteDoors(*to); break;
4359 case ScreenEnemies: Map.PasteEnemies(*to); break;
4360 case ScreenFFCombos: Map.PasteFFCombos(*to); break;
4361 case ScreenGuy: Map.PasteGuy(*to); break;
4362 case ScreenLayers: Map.PasteLayers(*to); break;
4363 case ScreenPalette: Map.PastePalette(*to); break;
4364 case ScreenPartial: Map.Paste(*to); break;
4365 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4366 case ScreenRoom: Map.PasteRoom(*to); break;
4367 case ScreenSecretCombos: Map.PasteSecretCombos(*to); break;
4368 case ScreenUnderCombo: Map.PasteUnderCombo(*to); break;
4369 case ScreenWarpLocations: Map.PasteWarpLocations(*to); break;
4370 case ScreenWarps: Map.PasteWarps(*to); break;
4371 }
4372 }
4373 else
4374 {
4375 Map.clearscr(view_scr);
4376 }
4377 refresh(rALL);
4378 }
4379
4380 void set_screen_command::execute()
4381 {
4382 if (screen)
4383 {
4384 copy_mapscr(Map.AbsoluteScr(view_map, view_scr), screen.get());
4385 }
4386 else
4387 {
4388 Map.clearscr(view_scr);
4389 }
4390 refresh(rALL);
4391 }
4392
4393 void set_screen_command::undo()
4394 {
4395 if (prev_screen)
4396 {
4397 copy_mapscr(Map.AbsoluteScr(view_map, view_scr), prev_screen.get());
4398 }
4399 else
4400 {
4401 Map.clearscr(view_scr);
4402 }
4403 refresh(rALL);
4404 }
4405
4406 int set_screen_command::size()
4407 {
4408 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4409 }
4410
4411 extern byte relational_tile_grid[11+(rtgyo*2)][16+(rtgxo*2)];
4412
4413 void tile_grid_draw_command::execute()
4414 {
4415 util::copy_2d_array<byte, 15, 20>(tile_grid, relational_tile_grid);
4416 }
4417
4418 void tile_grid_draw_command::undo()
4419 {
4420 util::copy_2d_array<byte, 15, 20>(prev_tile_grid, relational_tile_grid);
4421 }
4422
4423 static std::shared_ptr<list_command> current_list_command;
4424 void zmap::StartListCommand()
4425 {
4426 ASSERT(!current_list_command);
4427 current_list_command.reset(new list_command);
4428 }
4429
4430 void zmap::FinishListCommand()
4431 {
4432 if (current_list_command->commands.size() == 1)
4433 {
4434 undo_stack.push_back(current_list_command->commands[0]);
4435 }
4436 else if (current_list_command->commands.size() > 1)
4437 {
4438 undo_stack.push_back(current_list_command);
4439 }
4440 CapCommandHistory();
4441 current_list_command = nullptr;
4442 }
4443
4444 void zmap::RevokeListCommand()
4445 {
4446 current_list_command->undo();
4447 current_list_command = nullptr;
4448 }
4449
4450 bool zmap::InListCommand() const
4451 {
4452 return current_list_command ? true : false;
4453 }
4454
4455 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4456 {
4457 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4458 if (!skip_execute) command->execute();
4459 if (current_list_command)
4460 {
4461 current_list_command->commands.push_back(command);
4462 if (current_list_command->commands.size() == 1)
4463 {
4464 current_list_command->view_map = command->view_map;
4465 current_list_command->view_scr = command->view_scr;
4466 }
4467 }
4468 else
4469 {
4470 undo_stack.push_back(command);
4471 CapCommandHistory();
4472 }
4473 saved = false;
4474 }
4475
4476 void zmap::UndoCommand()
4477 {
4478 if (undo_stack.size() <= 0) return;
4479
4480 // If not currently looking at the associated screen, first change the view
4481 // and wait for the next call to actually undo this command.
4482 auto command = undo_stack.back();
4483 if (command->view_map != Map.getCurrMap() || command->view_scr != Map.getCurrScr())
4484 {
4485 setCurrentView(command->view_map, command->view_scr);
4486 return;
4487 }
4488
4489 command->undo();
4490 redo_stack.push(command);
4491 undo_stack.pop_back();
4492 saved = false;
4493 }
4494
4495 void zmap::RedoCommand()
4496 {
4497 if (redo_stack.size() <= 0) return;
4498
4499 // If not currently looking at the associated screen, first change the view
4500 // and wait for the next call to actually execute this command.
4501 auto command = redo_stack.top();
4502 if (command->view_map != Map.getCurrMap() || command->view_scr != Map.getCurrScr())
4503 {
4504 setCurrentView(command->view_map, command->view_scr);
4505 return;
4506 }
4507
4508 command->execute();
4509 undo_stack.push_back(command);
4510 redo_stack.pop();
4511 saved = false;
4512 }
4513
4514 9 void zmap::ClearCommandHistory()
4515 {
4516 9 current_list_command = nullptr;
4517 9 undo_stack = std::deque<std::shared_ptr<user_input_command>>();
4518 9 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4519 9 }
4520
4521 // Extra amount is from mapscr's vectors.
4522 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4523 // Allow the undo system to use roughly 100 MB of memory.
4524 // This doesn't count the memory used by commands that don't store a mapscr,
4525 // but that should be negligible.
4526 9 static int max_command_size = 100e6 / size_of_mapscr;
4527 void zmap::CapCommandHistory()
4528 {
4529 int size;
4530 do
4531 {
4532 size = 0;
4533 for (auto command : undo_stack)
4534 {
4535 size += command->size();
4536 }
4537 if (size > max_command_size) undo_stack.pop_front();
4538 } while (size > max_command_size);
4539 }
4540
4541 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4542 {
4543 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4544 if(!mapscr_ptr) return;
4545 std::shared_ptr<set_combo_command> command(new set_combo_command);
4546 command->view_map = currmap;
4547 command->view_scr = currscr;
4548 command->map = map;
4549 command->scr = scr;
4550 command->pos = pos;
4551 command->combo = combo;
4552 command->cset = cset;
4553 command->prev_combo = mapscr_ptr->data[pos];
4554 command->prev_cset = mapscr_ptr->cset[pos];
4555 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4556 {
4557 // nothing to do...
4558 return;
4559 }
4560
4561 ExecuteCommand(command);
4562 }
4563
4564 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4565 {
4566 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4567 if(!mapscr_ptr) return;
4568
4569 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4570
4571 std::array<int, 2> inita_arr;
4572 std::copy(std::begin(mapscr_ptr->ffcs[i].inita), std::end(mapscr_ptr->ffcs[i].inita), inita_arr.begin());
4573 std::array<int, 8> initd_arr;
4574 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4575
4576 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4577
4578 command->view_map = currmap;
4579 command->view_scr = currscr;
4580 command->map = map;
4581 command->scr = scr;
4582 command->i = i;
4583 command->data = data;
4584 command->prev_data = prev_data;
4585 if (data == prev_data)
4586 {
4587 // nothing to do...
4588 return;
4589 }
4590
4591 ExecuteCommand(command);
4592 }
4593
4594 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4595 {
4596 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4597 if(!mapscr_ptr) return;
4598 std::shared_ptr<set_flag_command> command(new set_flag_command);
4599 command->view_map = currmap;
4600 command->view_scr = currscr;
4601 command->map = map;
4602 command->scr = scr;
4603 command->pos = pos;
4604 command->flag = flag;
4605 command->prev_flag = mapscr_ptr->sflag[pos];
4606 if (command->flag == command->prev_flag)
4607 {
4608 // nothing to do...
4609 return;
4610 }
4611
4612 ExecuteCommand(command);
4613 }
4614
4615 void zmap::DoSetDoorCommand(int scr, int side, int door)
4616 {
4617 if(screens[scr].door[side] == door)
4618 return;
4619 std::shared_ptr<set_door_command> command(new set_door_command);
4620 command->view_map = currmap;
4621 command->view_scr = scr;
4622 command->side = side;
4623 command->door = door;
4624 command->prev_door = screens[scr].door[side];
4625
4626 ExecuteCommand(command);
4627 }
4628 void zmap::DoSetDCSCommand(int dcs)
4629 {
4630 if(screens[currscr].door_combo_set == dcs)
4631 return;
4632 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4633 command->view_map = currmap;
4634 command->view_scr = currscr;
4635 command->dcs = dcs;
4636 command->prev_dcs = screens[currscr].door_combo_set;
4637
4638 ExecuteCommand(command);
4639 }
4640
4641 void zmap::DoPasteScreenCommand(PasteCommandType type, int data)
4642 {
4643 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4644 command->view_map = currmap;
4645 command->view_scr = currscr;
4646 command->type = type;
4647 command->data = data;
4648 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4649
4650 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4651 {
4652 for (int i=0; i < 128; i++)
4653 {
4654 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4655 }
4656 }
4657 else
4658 {
4659 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[currscr])));
4660 }
4661
4662 ExecuteCommand(command);
4663 }
4664
4665 void zmap::DoClearScreenCommand()
4666 {
4667 std::shared_ptr<set_screen_command> command(new set_screen_command);
4668 command->view_map = currmap;
4669 command->view_scr = currscr;
4670 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[currscr]));
4671 command->screen = std::shared_ptr<mapscr>(nullptr);
4672
4673 ExecuteCommand(command);
4674 }
4675
4676 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int scr)
4677 {
4678 std::shared_ptr<set_screen_command> command(new set_screen_command);
4679 command->view_map = currmap;
4680 command->view_scr = currscr;
4681 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.CurrScr()));
4682 Template(floorcombo, floorcset, scr);
4683 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.CurrScr()));
4684
4685 ExecuteCommand(command, true);
4686 }
4687
4688 void zmap::Copy()
4689 {
4690 if(screens[currscr].valid&mVALID)
4691 {
4692 copy_mapscr(&copymapscr, &screens[currscr]);
4693 //copymapscr=screens[currscr];
4694 can_paste=true;
4695 copymap=currmap;
4696 copyscr=currscr;
4697 copyscrdata = zinit.screen_data[currmap*MAPSCRS+currscr];
4698 copyffc = -1;
4699 }
4700 }
4701
4702 void zmap::CopyFFC(int32_t n)
4703 {
4704 if(screens[currscr].valid&mVALID)
4705 {
4706 copy_mapscr(&copymapscr, &screens[currscr]);
4707 // Can't paste the screen itself
4708 can_paste = false;
4709 copymap=currmap;
4710 copyscr=currscr;
4711 copyffc = n;
4712 }
4713 }
4714
4715 void zmap::Paste(const mapscr& copymapscr)
4716 {
4717 if(can_paste)
4718 {
4719 int32_t oldcolor=getcolor();
4720
4721 if(!(screens[currscr].valid&mVALID))
4722 {
4723 screens[currscr].valid |= mVALID;
4724 screens[currscr].color = copymapscr.color;
4725 }
4726
4727 screens[currscr].door_combo_set = copymapscr.door_combo_set;
4728
4729 for(int32_t i=0; i<4; i++)
4730 {
4731 screens[currscr].door[i]=copymapscr.door[i];
4732 }
4733
4734 for(int32_t i=0; i<176; i++)
4735 {
4736 screens[currscr].data[i] = copymapscr.data[i];
4737 screens[currscr].cset[i] = copymapscr.cset[i];
4738 screens[currscr].sflag[i] = copymapscr.sflag[i];
4739 }
4740
4741 int32_t newcolor=getcolor();
4742 loadlvlpal(newcolor);
4743
4744 if(newcolor!=oldcolor)
4745 {
4746 rebuild_trans_table();
4747 }
4748
4749 saved=false;
4750 }
4751 }
4752
4753 void zmap::PasteUnderCombo(const mapscr& copymapscr)
4754 {
4755 if(can_paste)
4756 {
4757 screens[currscr].undercombo = copymapscr.undercombo;
4758 screens[currscr].undercset = copymapscr.undercset;
4759 saved=false;
4760 }
4761 }
4762
4763 void zmap::PasteSecretCombos(const mapscr& copymapscr)
4764 {
4765 if(can_paste)
4766 {
4767 for(int32_t i=0; i<128; i++)
4768 {
4769 screens[currscr].secretcombo[i] = copymapscr.secretcombo[i];
4770 screens[currscr].secretcset[i] = copymapscr.secretcset[i];
4771 screens[currscr].secretflag[i] = copymapscr.secretflag[i];
4772 }
4773
4774 saved=false;
4775 }
4776 }
4777
4778 // TODO const mapscr& copymapscr
4779 void zmap::PasteFFCombos(mapscr& copymapscr)
4780 {
4781 if(can_paste)
4782 {
4783 word c = copymapscr.numFFC();
4784 for(word i=0; i<c; i++)
4785 screens[currscr].ffcs[i] = copymapscr.ffcs[i];
4786 for(word i = c; i < MAXFFCS; ++i)
4787 screens[currscr].ffcs[i].clear();
4788 screens[currscr].ffcCountMarkDirty();
4789
4790 saved=false;
4791 }
4792 }
4793
4794 void zmap::PasteWarps(const mapscr& copymapscr)
4795 {
4796 if(can_paste)
4797 {
4798 screens[currscr].sidewarpindex = copymapscr.sidewarpindex;
4799
4800 for(int32_t i=0; i<4; i++)
4801 {
4802 screens[currscr].tilewarptype[i] = copymapscr.tilewarptype[i];
4803 screens[currscr].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4804 screens[currscr].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4805 screens[currscr].sidewarptype[i] = copymapscr.sidewarptype[i];
4806 screens[currscr].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4807 screens[currscr].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4808 screens[currscr].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4809 screens[currscr].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4810 screens[currscr].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4811 screens[currscr].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4812 }
4813
4814 saved=false;
4815 }
4816 }
4817
4818 void zmap::PasteScreenData(const mapscr& copymapscr)
4819 {
4820 if(can_paste)
4821 {
4822 screens[currscr].csensitive = copymapscr.csensitive;
4823 screens[currscr].oceansfx = copymapscr.oceansfx;
4824 screens[currscr].bosssfx = copymapscr.bosssfx;
4825 screens[currscr].secretsfx = copymapscr.secretsfx;
4826 screens[currscr].holdupsfx = copymapscr.holdupsfx;
4827 screens[currscr].flags = copymapscr.flags;
4828 screens[currscr].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4829 screens[currscr].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4830 screens[currscr].flags3 = copymapscr.flags3;
4831 screens[currscr].flags4 = copymapscr.flags4;
4832 screens[currscr].flags5 = copymapscr.flags5;
4833 screens[currscr].flags6 = copymapscr.flags6;
4834 screens[currscr].flags7 = copymapscr.flags7;
4835 screens[currscr].flags8 = copymapscr.flags8;
4836 screens[currscr].flags9 = copymapscr.flags9;
4837 screens[currscr].flags10 = copymapscr.flags10;
4838 screens[currscr].item = copymapscr.item;
4839 screens[currscr].hasitem = copymapscr.hasitem;
4840 screens[currscr].itemx = copymapscr.itemx;
4841 screens[currscr].itemy = copymapscr.itemy;
4842 screens[currscr].nextmap = copymapscr.nextmap;
4843 screens[currscr].nextscr = copymapscr.nextscr;
4844 screens[currscr].nocarry = copymapscr.nocarry;
4845 screens[currscr].noreset = copymapscr.noreset;
4846 screens[currscr].path[0] = copymapscr.path[0];
4847 screens[currscr].path[1] = copymapscr.path[1];
4848 screens[currscr].path[2] = copymapscr.path[2];
4849 screens[currscr].path[3] = copymapscr.path[3];
4850 screens[currscr].pattern = copymapscr.pattern;
4851 screens[currscr].exitdir = copymapscr.exitdir;
4852 screens[currscr].enemyflags = copymapscr.enemyflags;
4853 screens[currscr].screen_midi = copymapscr.screen_midi;
4854 screens[currscr].stairx = copymapscr.stairx;
4855 screens[currscr].stairy = copymapscr.stairy;
4856 screens[currscr].timedwarptics = copymapscr.timedwarptics;
4857 saved=false;
4858 }
4859 }
4860
4861 void zmap::PasteWarpLocations(const mapscr& copymapscr)
4862 {
4863 if(can_paste)
4864 {
4865 screens[currscr].warpreturnc = copymapscr.warpreturnc;
4866 screens[currscr].warparrivalx = copymapscr.warparrivalx;
4867 screens[currscr].warparrivaly = copymapscr.warparrivaly;
4868
4869 for(int32_t i=0; i<4; i++)
4870 {
4871 screens[currscr].warpreturnx[i] = copymapscr.warpreturnx[i];
4872 screens[currscr].warpreturny[i] = copymapscr.warpreturny[i];
4873 }
4874
4875 saved=false;
4876 }
4877 }
4878
4879 void zmap::PasteDoors(const mapscr& copymapscr)
4880 {
4881 if(can_paste)
4882 {
4883 for(int32_t i=0; i<4; i++)
4884 screens[currscr].door[i] = copymapscr.door[i];
4885
4886 screens[currscr].door_combo_set = copymapscr.door_combo_set;
4887 saved=false;
4888 }
4889 }
4890
4891 void zmap::PasteLayers(const mapscr& copymapscr)
4892 {
4893 if(can_paste)
4894 {
4895 for(int32_t i=0; i<6; i++)
4896 {
4897 screens[currscr].layermap[i] = copymapscr.layermap[i];
4898 screens[currscr].layerscreen[i] = copymapscr.layerscreen[i];
4899 screens[currscr].layeropacity[i] = copymapscr.layeropacity[i];
4900 }
4901
4902 saved=false;
4903 }
4904 }
4905
4906 void zmap::PasteRoom(const mapscr& copymapscr)
4907 {
4908 if(can_paste)
4909 {
4910 screens[currscr].room = copymapscr.room;
4911 screens[currscr].catchall = copymapscr.catchall;
4912 saved=false;
4913 }
4914 }
4915
4916 void zmap::PasteGuy(const mapscr& copymapscr)
4917 {
4918 if(can_paste)
4919 {
4920 screens[currscr].guy = copymapscr.guy;
4921 screens[currscr].guytile = copymapscr.guytile;
4922 screens[currscr].guycs = copymapscr.guycs;
4923 SETFLAG(screens[currscr].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4924 SETFLAG(screens[currscr].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4925 screens[currscr].str = copymapscr.str;
4926 saved=false;
4927 }
4928 }
4929
4930 void zmap::PastePalette(const mapscr& copymapscr)
4931 {
4932 if(can_paste)
4933 {
4934 int32_t oldcolor=getcolor();
4935 screens[currscr].color = copymapscr.color;
4936 int32_t newcolor=getcolor();
4937 loadlvlpal(newcolor);
4938
4939 screens[currscr].valid|=mVALID;
4940
4941 if(newcolor!=oldcolor)
4942 {
4943 rebuild_trans_table();
4944 }
4945
4946 saved=false;
4947 }
4948 }
4949
4950 void zmap::PasteAll(const mapscr& copymapscr)
4951 {
4952 if(can_paste)
4953 {
4954 int32_t oldcolor=getcolor();
4955 copy_mapscr(&screens[currscr], &copymapscr);
4956 zinit.screen_data[currmap*MAPSCRS+currscr] = copyscrdata;
4957 //screens[currscr]=copymapscr;
4958 int32_t newcolor=getcolor();
4959 loadlvlpal(newcolor);
4960
4961 screens[currscr].valid|=mVALID;
4962
4963 if(newcolor!=oldcolor)
4964 {
4965 rebuild_trans_table();
4966 }
4967
4968 saved=false;
4969 }
4970 }
4971
4972
4973 void zmap::PasteToAll(const mapscr& copymapscr)
4974 {
4975 if(can_paste)
4976 {
4977 int32_t oldcolor=getcolor();
4978
4979 for(int32_t x=0; x<128; x++)
4980 {
4981 if(!(screens[x].valid&mVALID))
4982 {
4983 screens[x].valid |= mVALID;
4984 screens[x].color = copymapscr.color;
4985 }
4986
4987 for(int32_t i=0; i<176; i++)
4988 {
4989 screens[x].data[i] = copymapscr.data[i];
4990 screens[x].cset[i] = copymapscr.cset[i];
4991 screens[x].sflag[i] = copymapscr.sflag[i];
4992 }
4993 }
4994
4995 int32_t newcolor=getcolor();
4996 loadlvlpal(newcolor);
4997
4998 if(!(screens[currscr].valid&mVALID))
4999 {
5000 newcolor=-1;
5001 }
5002
5003 if(newcolor!=oldcolor)
5004 {
5005 rebuild_trans_table();
5006 }
5007
5008 saved=false;
5009 }
5010 }
5011
5012 void zmap::PasteAllToAll(const mapscr& copymapscr)
5013 {
5014 if(can_paste)
5015 {
5016 int32_t oldcolor=getcolor();
5017
5018 for(int32_t x=0; x<128; x++)
5019 {
5020 copy_mapscr(&screens[x], &copymapscr);
5021 zinit.screen_data[currmap*MAPSCRS+x] = copyscrdata;
5022 //screens[x]=copymapscr;
5023 }
5024
5025 int32_t newcolor=getcolor();
5026 loadlvlpal(newcolor);
5027
5028 if(!(screens[currscr].valid&mVALID))
5029 {
5030 newcolor=-1;
5031 }
5032
5033 if(newcolor!=oldcolor)
5034 {
5035 rebuild_trans_table();
5036 }
5037
5038 saved=false;
5039 }
5040 }
5041
5042 void zmap::PasteEnemies(const mapscr& copymapscr)
5043 {
5044 if(can_paste)
5045 {
5046 for(int32_t i=0; i<10; i++)
5047 screens[currscr].enemy[i]=copymapscr.enemy[i];
5048 }
5049 }
5050
5051 void zmap::setCopyFFC(int32_t n)
5052 {
5053 copyffc = n;
5054 }
5055
5056 void zmap::update_combo_cycling()
5057 {
5058 if(!prv_mode||!prv_cmbcycle)
5059 {
5060 return;
5061 }
5062
5063 int32_t x;
5064 int32_t newdata[176];
5065 int32_t newcset[176];
5066 bool restartanim[MAXCOMBOS] = {0};
5067
5068 for(int32_t i=0; i<176; i++)
5069 {
5070 newdata[i]=-1;
5071 newcset[i]=-1;
5072
5073 x=prvscr.data[i];
5074
5075 //time to restart
5076 if((combobuf[x].aclk>=combobuf[x].speed) &&
5077 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5078 (combobuf[x].nextcombo!=0))
5079 {
5080 newdata[i]=combobuf[x].nextcombo;
5081 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5082 newcset[i]=combobuf[x].nextcset;
5083 int32_t c = newdata[i];
5084
5085 if(combobuf[c].animflags & AF_CYCLE)
5086 {
5087 restartanim[c]=true;
5088 }
5089 }
5090 }
5091
5092 for(int32_t i=0; i<176; i++)
5093 {
5094 x=prvscr.data[i];
5095
5096 //time to restart
5097 if((combobuf[x].aclk>=combobuf[x].speed) &&
5098 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5099 (combobuf[x].nextcombo!=0))
5100 {
5101 newdata[i]=combobuf[x].nextcombo;
5102 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5103 newcset[i]=combobuf[x].nextcset;
5104 int32_t c = newdata[i];
5105
5106 if(combobuf[c].animflags & AF_CYCLE)
5107 {
5108 restartanim[c]=true;
5109 }
5110 }
5111 }
5112
5113 for(int32_t i=0; i<176; i++)
5114 {
5115 if(newdata[i]==-1)
5116 continue;
5117
5118 prvscr.data[i]=newdata[i];
5119 prvscr.cset[i]=newcset[i];
5120 }
5121
5122 word maxffc = prvscr.numFFC();
5123 for(word i=0; i<maxffc; i++)
5124 {
5125 ffcdata& ffc = prvscr.ffcs[i];
5126 newcombo const& cmb = combobuf[ffc.data];
5127
5128 //time to restart
5129 if((cmb.aclk>=cmb.speed) &&
5130 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5131 (cmb.nextcombo!=0))
5132 {
5133 ffc.data = cmb.nextcombo;
5134 if(!(cmb.animflags & AF_CYCLENOCSET))
5135 ffc.cset=cmb.nextcset;
5136
5137 if(combobuf[ffc.data].animflags & AF_CYCLE)
5138 {
5139 restartanim[ffc.data]=true;
5140 }
5141 prvscr.ffcs[i].data = ffc.data;
5142 prvscr.ffcs[i].cset=ffc.cset;
5143 }
5144 }
5145
5146
5147 if(get_qr(qr_CMBCYCLELAYERS))
5148 {
5149 for(int32_t j=0; j<6; j++)
5150 {
5151 if(!prvlayers[j].valid)
5152 continue;
5153
5154 for(int32_t i=0; i<176; i++)
5155 {
5156 newdata[i]=-1;
5157 newcset[i]=-1;
5158
5159 x=(prvlayers[j]).data[i];
5160
5161 //time to restart
5162 if((combobuf[x].aclk>=combobuf[x].speed) &&
5163 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5164 (combobuf[x].nextcombo!=0))
5165 {
5166 newdata[i]=combobuf[x].nextcombo;
5167 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5168 newcset[i]=combobuf[x].nextcset;
5169 int32_t c = newdata[i];
5170
5171 if(combobuf[c].animflags & AF_CYCLE)
5172 {
5173 restartanim[c]=true;
5174 }
5175 }
5176 }
5177
5178 for(int32_t i=0; i<176; i++)
5179 {
5180 x=(prvlayers[j]).data[i];
5181
5182 //time to restart
5183 if((combobuf[x].aclk>=combobuf[x].speed) &&
5184 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5185 (combobuf[x].nextcombo!=0))
5186 {
5187 newdata[i]=combobuf[x].nextcombo;
5188 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5189 newcset[i]=combobuf[x].nextcset;
5190 int32_t c = newdata[i];
5191
5192 if(combobuf[c].animflags & AF_CYCLE)
5193 {
5194 restartanim[c]=true;
5195 }
5196 }
5197 }
5198
5199 for(int32_t i=0; i<176; i++)
5200 {
5201 if(newdata[i]==-1)
5202 continue;
5203
5204 prvlayers[j].data[i]=newdata[i];
5205 prvlayers[j].cset[i]=newcset[i];
5206 }
5207 }
5208 }
5209
5210 for(int32_t i=0; i<MAXCOMBOS; i++)
5211 {
5212 if(restartanim[i])
5213 {
5214 combobuf[i].tile = combobuf[i].o_tile;
5215 combobuf[i].cur_frame=0;
5216 combobuf[i].aclk = 0;
5217 }
5218 }
5219 }
5220
5221 void zmap::update_freeform_combos()
5222 {
5223 if(!prv_mode||!prv_cmbcycle)
5224 {
5225 return;
5226 }
5227
5228 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5229 word maxffc = prvscr.numFFC();
5230 for(int32_t i=0; i<maxffc; i++)
5231 {
5232 if(!(prvscr.ffcs[i].flags&ffc_changer) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffc_stationary))
5233 {
5234 for(int32_t j=0; j<maxffc; j++)
5235 {
5236 if(i!=j)
5237 {
5238 if(prvscr.ffcs[j].flags&ffc_changer && prvscr.ffcs[j].data != 0)
5239 {
5240 if((((prvscr.ffcs[j].x.getInt())!=ffposx[i])||((prvscr.ffcs[j].y.getInt())!=ffposy[i]))&&(prvscr.ffcs[i].link==0))
5241 {
5242 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),ffprvx[i],ffprvy[i],prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5243 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(ffprvx[i]>-10000000&&ffprvy[i]>-10000000))
5244 {
5245 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5246 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5247 if(prvscr.ffcs[j].flags&ffc_changethis)
5248 {
5249 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5250 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5251 }
5252
5253 if(prvscr.ffcs[j].flags&ffc_changenext)
5254 prvscr.ffcs[i].data += 1;
5255
5256 if(prvscr.ffcs[j].flags&ffc_changeprev)
5257 prvscr.ffcs[i].data -= 1;
5258
5259 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5260 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5261 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5262
5263 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5264 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5265 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5266 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5267
5268 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5269 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5270 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5271 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5272 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5273
5274 if(prvscr.ffcs[i].flags&ffc_carryover)
5275 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffc_carryover;
5276 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5277
5278 prvscr.ffcs[i].flags&=~ffc_changer;
5279 ffposx[i]=(prvscr.ffcs[j].x.getInt());
5280 ffposy[i]=(prvscr.ffcs[j].y.getInt());
5281
5282 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5283 {
5284 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5285 }
5286
5287 if((prvscr.ffcs[j].flags&ffc_swapnext)||(prvscr.ffcs[j].flags&ffc_swapprev))
5288 {
5289 int32_t k=0;
5290
5291 if(prvscr.ffcs[j].flags&ffc_swapnext)
5292 k=j<(MAXFFCS-1)?j+1:0;
5293
5294 if(prvscr.ffcs[j].flags&ffc_swapprev)
5295 k=j>0?j-1:(MAXFFCS-1);
5296
5297 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5298 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5299 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5300 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5301 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5302 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5303 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5304 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5305 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5306 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5307 }
5308 }
5309 }
5310 }
5311 }
5312 }
5313
5314 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5315 {
5316 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5317 {
5318 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5319 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5320 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5321 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5322 }
5323 else
5324 {
5325 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5326 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5327 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5328 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5329 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5330 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5331
5332 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5333 {
5334 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5335
5336 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5337
5338 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5339
5340 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5341 }
5342 }
5343 }
5344 else
5345 {
5346 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5347 prvscr.ffcs[i].delay--;
5348 }
5349
5350 if(prvscr.ffcs[i].x<-32)
5351 {
5352 if(prvscr.flags6&fWRAPAROUNDFF)
5353 {
5354 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5355 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5356 }
5357 else
5358 {
5359 prvscr.ffcs[i].data = 0;
5360 prvscr.ffcs[i].flags&=~ffc_carryover;
5361 }
5362 }
5363
5364 if(prvscr.ffcs[i].y<-32)
5365 {
5366 if(prvscr.flags6&fWRAPAROUNDFF)
5367 {
5368 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5369 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5370 }
5371 else
5372 {
5373 prvscr.ffcs[i].data = 0;
5374 prvscr.ffcs[i].flags&=~ffc_carryover;
5375 }
5376 }
5377
5378 if(prvscr.ffcs[i].x>=288)
5379 {
5380 if(prvscr.flags6&fWRAPAROUNDFF)
5381 {
5382 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5383 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5384 }
5385 else
5386 {
5387 prvscr.ffcs[i].data = 0;
5388 prvscr.ffcs[i].flags&=~ffc_carryover;
5389 }
5390 }
5391
5392 if(prvscr.ffcs[i].y>=208)
5393 {
5394 if(prvscr.flags6&fWRAPAROUNDFF)
5395 {
5396 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5397 ffprvy[i] = prvscr.ffcs[i].x.getZLong();
5398 }
5399 else
5400 {
5401 prvscr.ffcs[i].data = 0;
5402 prvscr.ffcs[i].flags&=~ffc_carryover;
5403 }
5404 }
5405
5406 }
5407 }
5408 }
5409
5410 void zmap::goto_dmapscr(int dmap, int scr)
5411 {
5412 setCurrMap(DMaps[dmap].map);
5413 setCurrScr(scr+DMaps[dmap].xoff);
5414 }
5415 void zmap::goto_mapscr(int map, int scr)
5416 {
5417 setCurrMap(map);
5418 setCurrScr(scr);
5419 }
5420
5421 void zmap::dowarp(int32_t type, int32_t index)
5422 {
5423 set_warpback();
5424 if(type==0)
5425 {
5426
5427 int32_t dmap=screens[currscr].tilewarpdmap[index];
5428 int32_t scr=screens[currscr].tilewarpscr[index];
5429
5430 switch(screens[currscr].tilewarptype[index])
5431 {
5432 case wtCAVE:
5433 case wtNOWARP:
5434 break;
5435
5436 default:
5437 goto_dmapscr(dmap, scr);
5438 break;
5439 }
5440 }
5441 else if(type==1)
5442 {
5443 int32_t dmap=screens[currscr].sidewarpdmap[index];
5444 int32_t scr=screens[currscr].sidewarpscr[index];
5445
5446 switch(screens[currscr].sidewarptype[index])
5447 {
5448 case wtCAVE:
5449 case wtNOWARP:
5450 break;
5451
5452 default:
5453 goto_dmapscr(dmap, scr);
5454 break;
5455 }
5456 }
5457 }
5458
5459 extern int32_t prv_twon;
5460
5461 void zmap::prv_dowarp(int32_t type, int32_t index)
5462 {
5463 if(type==0)
5464 {
5465
5466 int32_t dmap=prvscr.tilewarpdmap[index];
5467 int32_t scr=prvscr.tilewarpscr[index];
5468
5469 switch(prvscr.tilewarptype[index])
5470 {
5471 case wtCAVE:
5472 case wtNOWARP:
5473 break;
5474
5475 default:
5476 //setCurrMap(DMaps[dmap].map);
5477 //setCurrScr(scr+DMaps[dmap].xoff);
5478 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5479 loadlvlpal(getcolor());
5480 rebuild_trans_table();
5481 //prv_cmbcycle=0;
5482 break;
5483 }
5484 }
5485 else if(type==1)
5486 {
5487 int32_t dmap=prvscr.sidewarpdmap[index];
5488 int32_t scr=prvscr.sidewarpscr[index];
5489
5490 switch(prvscr.sidewarptype[index])
5491 {
5492 case wtCAVE:
5493 case wtNOWARP:
5494 break;
5495
5496 default:
5497 //setCurrMap(DMaps[dmap].map);
5498 //setCurrScr(scr+DMaps[dmap].xoff);
5499 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5500 loadlvlpal(getcolor());
5501 rebuild_trans_table();
5502 //prv_cmbcycle=0;
5503 break;
5504 }
5505 }
5506
5507 if(prv_twon)
5508 {
5509 prv_time=get_prvscr()->timedwarptics;
5510 }
5511
5512 //also reset FFC information (so that changers will work correctly) -DD
5513 memset(ffposx,0xFF,sizeof(int16_t)*32);
5514 memset(ffposy,0xFF,sizeof(int16_t)*32);
5515 memset(ffprvx,0xFF,sizeof(float)*32);
5516 memset(ffprvy,0xFF,sizeof(float)*32);
5517 }
5518
5519 void zmap::dowarp2(int32_t ring,int32_t index)
5520 {
5521 set_warpback();
5522 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5523 }
5524
5525 void zmap::set_warpback()
5526 {
5527 warpbackmap = currmap;
5528 warpbackscreen = currscr;
5529 }
5530 bool zmap::has_warpback()
5531 {
5532 return warpbackmap && warpbackscreen
5533 && !(warpbackmap == currmap && warpbackscreen == currscr);
5534 }
5535 void zmap::warpback()
5536 {
5537 if(!has_warpback())
5538 return;
5539 int m = currmap, s = currscr;
5540 goto_mapscr(*warpbackmap, *warpbackscreen);
5541 warpbackmap = m;
5542 warpbackscreen = s;
5543 }
5544
5545 bool save_msgstrs(const char *path)
5546 {
5547 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5548
5549 if(!f)
5550 {
5551 return false;
5552 }
5553
5554 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5555 {
5556 pack_fclose(f);
5557 return true;
5558 }
5559
5560 pack_fclose(f);
5561 return false;
5562 }
5563
5564 1 bool save_strings_tsv(const char *path)
5565 {
5566 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5567
5568
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5569 {
5570 return false;
5571 }
5572
5573
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5574 {
5575 1 pack_fclose(f);
5576 1 return true;
5577 }
5578
5579 pack_fclose(f);
5580 return false;
5581 1 }
5582
5583 bool save_msgstrs_text(const char *path)
5584 {
5585 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5586
5587 if(!f)
5588 {
5589 return false;
5590 }
5591
5592 if(writestrings_text(f)==0)
5593 {
5594 pack_fclose(f);
5595 return true;
5596 }
5597
5598 pack_fclose(f);
5599 return false;
5600 }
5601
5602 bool load_msgstrs(const char *path, int32_t startstring)
5603 {
5604 //these are here to bypass compiler warnings about unused arguments
5605 startstring=startstring;
5606
5607 dword section_id;
5608 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5609
5610 if(!f)
5611 {
5612 return false;
5613 }
5614
5615 if(!p_mgetl(&section_id,f))
5616 {
5617 return false;
5618 }
5619
5620 if(section_id==ID_STRINGS)
5621 {
5622 if(readstrings(f, &header)==0)
5623 {
5624 pack_fclose(f);
5625 return true;
5626 }
5627 else
5628 {
5629 pack_fclose(f);
5630 return false;
5631 }
5632 }
5633
5634 pack_fclose(f);
5635 return false;
5636 }
5637
5638 bool load_strings_tsv(const char *path)
5639 {
5640 try
5641 {
5642 parse_strings_tsv(util::read_text_file(path));
5643 }
5644 catch (std::exception& ex)
5645 {
5646 InfoDialog("Import .tsv Error", ex.what()).show();
5647 return false;
5648 }
5649 return true;
5650 }
5651
5652 bool save_pals(const char *path)
5653 {
5654 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5655
5656 if(!f)
5657 {
5658 return false;
5659 }
5660
5661 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5662 {
5663 pack_fclose(f);
5664 return true;
5665 }
5666
5667 pack_fclose(f);
5668 return false;
5669 }
5670
5671 bool load_pals(const char *path, int32_t startcset)
5672 {
5673 dword section_id;
5674 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5675
5676 if(!f)
5677 {
5678 return false;
5679 }
5680
5681 if(!p_mgetl(&section_id,f))
5682 {
5683 return false;
5684 }
5685
5686 if(section_id==ID_CSETS)
5687 {
5688 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5689 {
5690 pack_fclose(f);
5691 loadlvlpal(Color);
5692 return true;
5693 }
5694 else
5695 {
5696 pack_fclose(f);
5697 return false;
5698 }
5699 }
5700
5701 return false;
5702 }
5703
5704 bool save_dmaps(const char *path)
5705 {
5706 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5707
5708 if(!f)
5709 {
5710 return false;
5711 }
5712
5713 if(writedmaps(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXDMAPS)==0)
5714 {
5715 pack_fclose(f);
5716 return true;
5717 }
5718
5719 pack_fclose(f);
5720 return false;
5721 }
5722
5723 bool load_dmaps(const char *path, int32_t startdmap)
5724 {
5725 dword section_id;
5726 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5727
5728 if(!f)
5729 {
5730 return false;
5731 }
5732
5733 if(!p_mgetl(&section_id,f))
5734 {
5735 return false;
5736 }
5737
5738 if(section_id==ID_DMAPS)
5739 {
5740 if(readdmaps(f, NULL, 0x250, 33, startdmap, MAXDMAPS-startdmap)==0)
5741 {
5742 pack_fclose(f);
5743 return true;
5744 }
5745 else
5746 {
5747 pack_fclose(f);
5748 return false;
5749 }
5750 }
5751
5752 return false;
5753 }
5754 bool save_combos(const char *path)
5755 {
5756 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5757
5758 if(!f)
5759 {
5760 return false;
5761 }
5762
5763 reset_combo_animations();
5764 reset_combo_animations2();
5765
5766 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)==0)
5767 {
5768 pack_fclose(f);
5769 return true;
5770 }
5771
5772 pack_fclose(f);
5773 return false;
5774 }
5775
5776 bool load_combos(const char *path, int32_t startcombo)
5777 {
5778 dword section_id;
5779 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5780
5781 if(!f)
5782 {
5783 return false;
5784 }
5785
5786 if(!p_mgetl(&section_id,f))
5787 {
5788 return false;
5789 }
5790
5791 if(section_id==ID_COMBOS)
5792 {
5793 if(readcombos(f, NULL, 0x250, 33, startcombo, MAXCOMBOS-startcombo)==0)
5794 {
5795 pack_fclose(f);
5796 return true;
5797 }
5798 else
5799 {
5800 pack_fclose(f);
5801 return false;
5802 }
5803 }
5804
5805 return false;
5806 }
5807
5808 bool save_tiles(const char *path)
5809 {
5810 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5811
5812 if(!f)
5813 {
5814 return false;
5815 }
5816
5817 // reset_combo_animations();
5818 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)==0)
5819 {
5820 pack_fclose(f);
5821 return true;
5822 }
5823
5824 pack_fclose(f);
5825 return false;
5826 }
5827
5828 bool load_tiles(const char *path, int32_t starttile)
5829 {
5830 dword section_id;
5831 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5832
5833 if(!f)
5834 {
5835 return false;
5836 }
5837
5838 if(!p_mgetl(&section_id,f))
5839 {
5840 return false;
5841 }
5842
5843 if(section_id==ID_TILES)
5844 {
5845 if(readtiles(f, newtilebuf, NULL, 0x250, 33, starttile, NEWMAXTILES-starttile, false)==0)
5846 {
5847 pack_fclose(f);
5848 return true;
5849 }
5850 else
5851 {
5852 pack_fclose(f);
5853 init_tiles(true, &header);
5854 return false;
5855 }
5856 }
5857
5858 return false;
5859 }
5860
5861 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5862 bool save_guys(const char *path)
5863 {
5864 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5865
5866 if(!f)
5867 {
5868 return false;
5869 }
5870
5871 /*
5872 int32_t id = ID_GUYS;
5873 if(!p_mputl(id,f))
5874 {
5875 return false;
5876 }
5877 */
5878
5879 zquestheader h;
5880 h.zelda_version = 0x250;
5881 h.build = 21;
5882
5883 if(writeguys(f, &h)==0)
5884 {
5885 pack_fclose(f);
5886 return true;
5887 }
5888
5889 pack_fclose(f);
5890 return false;
5891 }
5892
5893 bool load_guys(const char *path)
5894 {
5895 dword section_id;
5896 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5897
5898 if(!f)
5899 {
5900 return false;
5901 }
5902
5903 if(!p_mgetl(&section_id,f))
5904 {
5905 pack_fclose(f);
5906 return false;
5907 }
5908
5909 zquestheader h;
5910 h.zelda_version = 0x250;
5911 h.build = 21;
5912
5913 if(section_id==ID_GUYS)
5914 {
5915 if(readguys(f, &h)==0)
5916 {
5917 pack_fclose(f);
5918 return true;
5919 }
5920 }
5921
5922 pack_fclose(f);
5923 return false;
5924 }
5925
5926
5927 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5928 bool save_combo_alias(const char *path)
5929 {
5930 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5931
5932 if(!f)
5933 {
5934 return false;
5935 }
5936
5937 zquestheader h;
5938 h.zelda_version = 0x250;
5939 h.build = 21;
5940
5941 if(writecomboaliases(f, 0, 0)==0)
5942 {
5943 pack_fclose(f);
5944 return true;
5945 }
5946
5947 pack_fclose(f);
5948 return false;
5949 }
5950
5951 bool load_combo_alias(const char *path)
5952 {
5953 dword section_id;
5954 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5955
5956 if(!f)
5957 {
5958 return false;
5959 }
5960
5961 if(!p_mgetl(&section_id,f))
5962 {
5963 pack_fclose(f);
5964 return false;
5965 }
5966
5967 zquestheader h;
5968 h.zelda_version = 0x250;
5969 h.build = 21;
5970
5971 if(section_id==ID_COMBOALIASES)
5972 {
5973 if(readcomboaliases(f, &h, 0, 0)==0)
5974 {
5975 pack_fclose(f);
5976 return true;
5977 }
5978 }
5979
5980 pack_fclose(f);
5981 return false;
5982 }
5983
5984 bool load_zgp(const char *path)
5985 {
5986 dword section_id;
5987 dword section_version;
5988 dword section_cversion;
5989 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5990
5991 if(!f)
5992 return false;
5993
5994 if(!p_mgetl(&section_id,f))
5995 {
5996 pack_fclose(f);
5997 return false;
5998 }
5999
6000 if(section_id!=ID_GRAPHICSPACK)
6001 {
6002 pack_fclose(f);
6003 return false;
6004 }
6005
6006 //section version info
6007 if(!p_igetw(&section_version,f))
6008 {
6009 return 2;
6010 }
6011
6012 if(!p_igetw(&section_cversion,f))
6013 {
6014 return 3;
6015 }
6016
6017 //tiles
6018 if(!p_mgetl(&section_id,f))
6019 {
6020 pack_fclose(f);
6021 return false;
6022 }
6023
6024 if(section_id==ID_TILES)
6025 {
6026 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
6027 {
6028 pack_fclose(f);
6029 init_tiles(true, &header);
6030 return false;
6031 }
6032 }
6033 else
6034 {
6035 pack_fclose(f);
6036 return false;
6037 }
6038
6039 //combos
6040 if(!p_mgetl(&section_id,f))
6041 {
6042 pack_fclose(f);
6043 return false;
6044 }
6045
6046 if(section_id==ID_COMBOS)
6047 {
6048 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6049 {
6050 pack_fclose(f);
6051 return false;
6052 }
6053 }
6054 else
6055 {
6056 pack_fclose(f);
6057 return false;
6058 }
6059
6060 //palettes
6061 if(!p_mgetl(&section_id,f))
6062 {
6063 pack_fclose(f);
6064 return false;
6065 }
6066
6067 if(section_id==ID_CSETS)
6068 {
6069 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6070 {
6071 pack_fclose(f);
6072 return false;
6073 }
6074 }
6075 else
6076 {
6077 pack_fclose(f);
6078 return false;
6079 }
6080
6081 //items
6082 if(!p_mgetl(&section_id,f))
6083 {
6084 pack_fclose(f);
6085 return false;
6086 }
6087
6088 if(section_id==ID_ITEMS)
6089 {
6090 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
6091 {
6092 pack_fclose(f);
6093 return false;
6094 }
6095 }
6096 else
6097 {
6098 pack_fclose(f);
6099 return false;
6100 }
6101
6102 //weapons
6103 if(!p_mgetl(&section_id,f))
6104 {
6105 pack_fclose(f);
6106 return false;
6107 }
6108
6109 if(section_id==ID_WEAPONS)
6110 {
6111 if(readweapons(f, &header)!=0)
6112 {
6113 pack_fclose(f);
6114 return false;
6115 }
6116 }
6117 else
6118 {
6119 pack_fclose(f);
6120 return false;
6121 }
6122
6123 //read the triforce pieces info and make sure it worked
6124 //really do this?
6125
6126 //read the game icons info and make sure it worked
6127 if(!p_mgetl(&section_id,f))
6128 {
6129 pack_fclose(f);
6130 return false;
6131 }
6132
6133 if(section_id==ID_ICONS)
6134 {
6135 if(readgameicons(f, &header, &QMisc)!=0)
6136 {
6137 pack_fclose(f);
6138 return false;
6139 }
6140 }
6141 else
6142 {
6143 pack_fclose(f);
6144 return false;
6145 }
6146
6147 //read the misc colors info and map styles info and make sure it worked
6148 if(!p_mgetl(&section_id,f))
6149 {
6150 pack_fclose(f);
6151 return false;
6152 }
6153
6154 if(section_id==ID_COLORS)
6155 {
6156 if(readmisccolors(f, &header, &QMisc)!=0)
6157 {
6158 pack_fclose(f);
6159 return false;
6160 }
6161 }
6162 else
6163 {
6164 pack_fclose(f);
6165 return false;
6166 }
6167
6168 //read the door combo sets and make sure it worked
6169 if(!p_mgetl(&section_id,f))
6170 {
6171 pack_fclose(f);
6172 return false;
6173 }
6174
6175 if(section_id==ID_DOORS)
6176 {
6177 if(readdoorcombosets(f, &header)!=0)
6178 {
6179 pack_fclose(f);
6180 return false;
6181 }
6182 }
6183 else
6184 {
6185 pack_fclose(f);
6186 return false;
6187 }
6188
6189 //read the template screens and make sure it worked
6190 //really do this?
6191
6192 //yay! it worked! close the file and say everything was ok.
6193 loadlvlpal(Color);
6194 setup_combo_animations();
6195 setup_combo_animations2();
6196 pack_fclose(f);
6197 return true;
6198 }
6199
6200 bool save_zgp(const char *path)
6201 {
6202 reset_combo_animations();
6203 reset_combo_animations2();
6204
6205 //open the file
6206 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6207
6208 if(!f)
6209 return false;
6210
6211 dword section_id=ID_GRAPHICSPACK;
6212 dword section_version=V_GRAPHICSPACK;
6213 dword section_cversion=CV_GRAPHICSPACK;
6214
6215 //section id
6216 if(!p_mputl(section_id,f))
6217 {
6218 return 1;
6219 }
6220
6221 //section version info
6222 if(!p_iputw(section_version,f))
6223 {
6224 return 2;
6225 }
6226
6227 if(!p_iputw(section_cversion,f))
6228 {
6229 return 3;
6230 }
6231
6232 //tiles
6233 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6234 {
6235 pack_fclose(f);
6236 return false;
6237 }
6238
6239 //combos
6240 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6241 {
6242 pack_fclose(f);
6243 return false;
6244 }
6245
6246 //palettes
6247 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6248 {
6249 pack_fclose(f);
6250 return false;
6251 }
6252
6253 //items
6254 if(writeitems(f, &header)!=0)
6255 {
6256 pack_fclose(f);
6257 return false;
6258 }
6259
6260 //weapons
6261 if(writeweapons(f, &header)!=0)
6262 {
6263 pack_fclose(f);
6264 return false;
6265 }
6266
6267 //write the triforce pieces info and make sure it worked
6268 //really do this?
6269
6270 //write the game icons info and make sure it worked
6271 if(writegameicons(f, &header)!=0)
6272 {
6273 pack_fclose(f);
6274 return false;
6275 }
6276
6277 //write the misc colors info and map styles info and make sure it worked
6278 if(writemisccolors(f, &header)!=0)
6279 {
6280 pack_fclose(f);
6281 return false;
6282 }
6283
6284 //write the door combo sets and make sure it worked
6285 if(writedoorcombosets(f, &header)!=0)
6286 {
6287 pack_fclose(f);
6288 return false;
6289 }
6290
6291 //write the template screens and make sure it worked
6292 //really do this?
6293
6294 pack_fclose(f);
6295 return true;
6296 }
6297
6298 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6299 {
6300 //open the file
6301 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6302
6303 if(!f)
6304 return false;
6305
6306 dword section_id=ID_SUBSCREEN;
6307 dword s_version=V_SUBSCREEN;
6308 dword s_cversion=CV_SUBSCREEN;
6309
6310 if(!p_mputl(section_id,f))
6311 {
6312 pack_fclose(f);
6313 return false;
6314 }
6315
6316 if(!p_iputw(s_version,f))
6317 {
6318 pack_fclose(f);
6319 return false;
6320 }
6321
6322 if(!p_iputw(s_cversion,f))
6323 {
6324 pack_fclose(f);
6325 return false;
6326 }
6327
6328 if(savefrom.write(f))
6329 {
6330 pack_fclose(f);
6331 return false;
6332 }
6333
6334 pack_fclose(f);
6335 return true;
6336 }
6337
6338 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6339 {
6340 //open the file
6341 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6342
6343 if(!f)
6344 return false;
6345
6346 dword section_id;
6347 dword s_version;
6348 dword s_cversion;
6349
6350 if(!p_mgetl(&section_id,f))
6351 {
6352 pack_fclose(f);
6353 return false;
6354 }
6355
6356 if(section_id!=ID_SUBSCREEN)
6357 {
6358 pack_fclose(f);
6359 return false;
6360 }
6361
6362 if(!p_igetw(&s_version,f))
6363 {
6364 pack_fclose(f);
6365 return false;
6366 }
6367
6368 if(!p_igetw(&s_cversion,f))
6369 {
6370 pack_fclose(f);
6371 return false;
6372 }
6373
6374 if(s_version < 8)
6375 {
6376 subscreen_group g;
6377 memset(&g,0,sizeof(subscreen_group));
6378 if(read_one_old_subscreen(f,&g,s_version)!=0)
6379 {
6380 pack_fclose(f);
6381 return false;
6382 }
6383 if(g.ss_type != loadto.sub_type)
6384 {
6385 pack_fclose(f);
6386 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6387 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6388 return false;
6389 }
6390 loadto.clear();
6391 if(g.objects[0].type != ssoNULL)
6392 loadto.load_old(g);
6393 }
6394 else
6395 {
6396 ZCSubscreen tmp = ZCSubscreen();
6397 if (tmp.read(f, s_version))
6398 {
6399 pack_fclose(f);
6400 return false;
6401 }
6402 if(tmp.sub_type != loadto.sub_type)
6403 {
6404 pack_fclose(f);
6405 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6406 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6407 return false;
6408 }
6409 loadto.clear();
6410 loadto = tmp;
6411 }
6412
6413 pack_fclose(f);
6414 return true;
6415 }
6416
6417 bool setMapCount2(int32_t c)
6418 {
6419 int32_t oldmapcount=map_count;
6420 int32_t currmap=Map.getCurrMap();
6421
6422 bound(c,1,MAXMAPS);
6423 map_count=c;
6424
6425 try
6426 {
6427 TheMaps.resize(c*MAPSCRS);
6428 Map.force_refr_pointer();
6429 map_autolayers.resize(c*6);
6430 }
6431 catch(...)
6432 {
6433 jwin_alert("Error","Failed to change map count.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6434 return false;
6435 }
6436
6437 bound(currmap,0,c-1);
6438 if(map_count>oldmapcount)
6439 {
6440 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6441 {
6442 Map.setCurrMap(mc);
6443
6444 for(int32_t ms=0; ms<MAPSCRS; ms++)
6445 {
6446 Map.clearscr(ms);
6447 }
6448 }
6449 Map.setCurrMap(currmap);
6450 }
6451 else
6452 {
6453 Map.setCurrMap(currmap);
6454 if(!layers_valid(Map.CurrScr()))
6455 fix_layers(Map.CurrScr(), false);
6456
6457 for(int32_t i=0; i<MAXDMAPS; i++)
6458 {
6459 if(DMaps[i].map>=map_count)
6460 {
6461 DMaps[i].map=map_count-1;
6462 }
6463 }
6464 }
6465
6466 return true;
6467 }
6468
6469 extern BITMAP *bmap;
6470
6471 static bool loading_file_new = false;
6472 1 int32_t init_quest()
6473 {
6474 char qstdat_string[2048];
6475 1 strcpy(qstdat_string, "modules/classic/default.qst");
6476
6477 char buf[2048];
6478
6479 1 loading_file_new = true;
6480 1 load_quest(qstdat_string);
6481 1 loading_file_new = false;
6482
6483 1 sprintf(buf,"ZC Editor - Untitled Quest");
6484 1 set_window_title(buf);
6485 1 zinit.last_map = 0;
6486 1 zinit.last_screen = 0;
6487
6488
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(bmap != NULL)
6489 {
6490 destroy_bitmap(bmap);
6491 bmap=NULL;
6492 }
6493
6494 1 return 0;
6495 }
6496
6497 void set_questpwd(std::string_view pwd, bool use_keyfile)
6498 {
6499 header.use_keyfile=use_keyfile;
6500
6501 // string_view actually has some quirks that make it less than ideal here.
6502 // It'd probably be best to replace it, but this works for now.
6503 memset(header.password, 0, 256);
6504 strcpy(header.password, pwd.data());
6505 header.dirty_password=true;
6506
6507 cvs_MD5Context ctx;
6508 cvs_MD5Init(&ctx);
6509 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6510 cvs_MD5Final(header.pwd_hash, &ctx);
6511 }
6512
6513
6514 bool is_null_pwd_hash(uint8_t *pwd_hash)
6515 {
6516 cvs_MD5Context ctx;
6517 uint8_t md5sum[16];
6518 char pwd[2]="";
6519
6520 cvs_MD5Init(&ctx);
6521 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6522 cvs_MD5Final(md5sum, &ctx);
6523
6524 return (memcmp(md5sum,pwd_hash,16)==0);
6525 }
6526
6527 static DIALOG pwd_dlg[] =
6528 {
6529 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6530 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6531 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6532 // 2 (filename)
6533 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6534 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6535 // 4 (challenge hash)
6536 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6537 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6538 // 6 (password)
6539 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6540 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6541 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6542 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6543 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6544 };
6545
6546 int32_t reverse_string(char* str)
6547 {
6548
6549 if(NULL==str)
6550 {
6551 return -1; //no string
6552 }
6553
6554 int32_t l=(int32_t)strlen(str)-1; //get the string length
6555
6556 if(1==l)
6557 {
6558 return 1;
6559 }
6560
6561 char c;
6562
6563 for(int32_t x=0; x < l; x++,l--)
6564 {
6565 c = str[x];
6566 str[x] = str[l];
6567 str[l] = c;
6568 }
6569
6570 return 0;
6571 }
6572
6573 #ifdef __GNUC__
6574 #pragma GCC diagnostic push
6575 #pragma GCC diagnostic ignored "-Wunreachable-code"
6576 #endif
6577
6578 9 int32_t quest_access(const char *filename, zquestheader *hdr)
6579 {
6580
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (is_headless())
6581 9 return 1;
6582
6583 #ifdef __EMSCRIPTEN__
6584 return 1;
6585 #endif
6586
6587 //Protection against compiling a release version with password protection off.
6588 static bool passguard = false;
6589
6590 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6591 #define MUST_HAVE_PASSWORD
6592 passguard = true;
6593 #endif
6594
6595 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6596 #if (defined _MSC_VER || defined _NPASS)
6597 return 1;
6598 #endif
6599 #endif
6600 if(devpwd()) return 1;
6601
6602 char hash_string[33];
6603
6604 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6605 {
6606 return 1;
6607 }
6608
6609 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6610 return true;
6611
6612 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6613 pwd_dlg[2].dp=get_filename(filename);
6614 cvs_MD5Context ctx;
6615 uint8_t md5sum[16]={0};
6616 char response[33]="";
6617 char prompt[256]="";
6618
6619 memcpy(md5sum, hdr->pwd_hash, 16);
6620
6621 for(int32_t i=0; i<300; ++i)
6622 {
6623 for(int32_t j=0; j<16; ++j)
6624 {
6625 sprintf(response+j*2, "%02x", md5sum[j]);
6626 }
6627
6628 if(i&1)
6629 {
6630 reverse_string(response);
6631 }
6632
6633 if(i==149)
6634 {
6635 strcpy(hash_string, response);
6636 }
6637
6638 cvs_MD5Init(&ctx);
6639 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6640 cvs_MD5Final(md5sum, &ctx);
6641 }
6642
6643 pwd_dlg[4].dp=hash_string;
6644
6645 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6646 {
6647 sprintf(prompt,"%s",response);
6648 }
6649
6650 pwd_dlg[6].dp=prompt;
6651
6652 large_dialog(pwd_dlg);
6653
6654 int32_t cancel = do_zqdialog(pwd_dlg,6);
6655
6656 if(cancel == 8)
6657 return 2;
6658
6659 bool ret=check_questpwd(hdr, prompt);
6660
6661 if(!ret)
6662 {
6663 ret=(strcmp(response,prompt)==0);
6664 }
6665 return ret ? 1 : 0;
6666 9 }
6667
6668 void set_rules(byte* newrules);
6669 8 void popup_bugfix_dlg(const char* cfg)
6670 {
6671 8 bool dont_show_again = zc_get_config("zquest",cfg,0);
6672
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if(!dont_show_again && hasCompatRulesEnabled())
6673 {
6674
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
24 AlertDialog("Apply New Bugfixes",
6675
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 "New bugfixes found that can be applied to this quest!"
6676 "\nWould you like to apply them?"
6677 "\n(Applies 'Bugfix' rule template, un-checking compat rules)",
6678 8 [&](bool ret,bool dsa)
6679 {
6680 if(ret)
6681 {
6682 applyRuleTemplate(ruletemplateFixCompat);
6683 }
6684 if(dsa)
6685 {
6686 zc_set_config("zquest",cfg,1);
6687 }
6688 },
6689
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 "Yes","No",
6690 0,false, //timeout - none
6691 true //"Don't show this again"
6692
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 ).show();
6693 8 }
6694 8 }
6695
6696 #ifdef __GNUC__
6697 #pragma GCC diagnostic pop
6698 #endif
6699
6700 // wrapper to reinitialize everything on an error
6701 9 int32_t load_quest(const char *filename, bool show_progress)
6702 {
6703 char buf[2048];
6704 // if(encrypted)
6705 // setPackfilePassword(datapwd);
6706 byte skip_flags[4];
6707
6708
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 9 times.
45 for(int32_t i=0; i<4; ++i)
6709 {
6710 36 skip_flags[i]=0;
6711 36 }
6712
2/2
✓ Branch 0 taken 6228 times.
✓ Branch 1 taken 9 times.
6237 for(int32_t i=0; i<qr_MAX; i++)
6713 6228 set_qr(i,0);
6714 9 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags);
6715
6716
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret!=qe_OK)
6717 {
6718 init_quest();
6719 }
6720 else
6721 {
6722 9 int32_t accessret = quest_access(filename, &header);
6723
6724
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(accessret != 1)
6725 {
6726 init_quest();
6727
6728 if(accessret == 0)
6729 ret=qe_pwd;
6730 else
6731 ret=qe_cancel;
6732 }
6733 else
6734 {
6735 9 Map.clear();
6736 9 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6737 9 Map.setCurrScr(zinit.last_screen);
6738 extern int32_t current_mappage;
6739 9 current_mappage = 0;
6740 9 bool found_default = false;
6741
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 65 times.
72 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6742 {
6743 65 auto &pg = map_page[q];
6744
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 9 times.
65 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6745 {
6746 2 current_mappage = q;
6747 2 break;
6748 }
6749
4/8
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
63 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6750 56 continue;
6751 else
6752 {
6753 7 current_mappage = q;
6754 7 found_default = true;
6755 }
6756 7 }
6757 9 refresh(rALL);
6758 9 refresh_pal();
6759 9 set_rules(quest_rules);
6760 9 saved = true;
6761
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
9 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6762 8 popup_bugfix_dlg("dsa_compatrule");
6763
6764
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(bmap != NULL)
6765 {
6766 destroy_bitmap(bmap);
6767 bmap=NULL;
6768 }
6769
6770
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 if (show_progress)
6771 {
6772 1 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6773 1 set_window_title(buf);
6774 1 }
6775 }
6776 }
6777
6778 9 Map.ClearCommandHistory();
6779
6780 9 return ret;
6781 }
6782
6783 int32_t load_tileset(const char *filename, dword tsetflags)
6784 {
6785 char buf[2048];
6786 byte skip_flags[4];
6787
6788 for(int32_t i=0; i<4; ++i)
6789 skip_flags[i]=0;
6790 for(int32_t i=0; i<qr_MAX; i++)
6791 set_qr(i,0);
6792 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6793
6794 if(ret!=qe_OK)
6795 init_quest();
6796 else
6797 {
6798 int32_t accessret = quest_access(filename, &header);
6799
6800 if(accessret != 1)
6801 {
6802 init_quest();
6803
6804 if(accessret == 0)
6805 ret=qe_pwd;
6806 else
6807 ret=qe_cancel;
6808 }
6809 else
6810 {
6811 Map.clear();
6812 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6813 Map.setCurrScr(zinit.last_screen);
6814 extern int32_t current_mappage;
6815 current_mappage = 0;
6816 bool found_default = false;
6817 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6818 {
6819 auto &pg = map_page[q];
6820 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6821 {
6822 current_mappage = q;
6823 break;
6824 }
6825 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6826 continue;
6827 else
6828 {
6829 current_mappage = q;
6830 found_default = true;
6831 }
6832 }
6833 refresh(rALL);
6834 refresh_pal();
6835 set_rules(quest_rules);
6836 if(!zc_get_config("zquest","auto_filenew_bugfixes",1))
6837 popup_bugfix_dlg("dsa_compatrule");
6838
6839 if(bmap != NULL)
6840 {
6841 destroy_bitmap(bmap);
6842 bmap=NULL;
6843 }
6844
6845 set_window_title("ZC Editor - Untitled Quest");
6846 first_save = saved = false;
6847 memset(filepath,0,255);
6848 memset(temppath,0,255);
6849 }
6850 }
6851
6852 Map.ClearCommandHistory();
6853
6854 return ret;
6855 }
6856
6857 60 bool write_midi(MIDI *m,PACKFILE *f)
6858 {
6859 int32_t c;
6860
6861
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
60 if(!p_mputw(m->divisions,f)) return false;
6862
6863
2/2
✓ Branch 0 taken 1920 times.
✓ Branch 1 taken 60 times.
1980 for(c=0; c<MIDI_TRACKS; c++)
6864 {
6865
1/2
✓ Branch 0 taken 1920 times.
✗ Branch 1 not taken.
1920 if(!p_mputl(m->track[c].len,f)) return false;
6866
6867
2/2
✓ Branch 0 taken 1428 times.
✓ Branch 1 taken 492 times.
1920 if(m->track[c].len > 0)
6868 {
6869
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6870 return false;
6871 492 }
6872 1920 }
6873
6874 60 return true;
6875 60 }
6876
6877 6 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6878 {
6879 6 dword section_id=ID_HEADER;
6880 6 dword section_version=V_HEADER;
6881 6 dword section_cversion=CV_HEADER;
6882 6 dword section_size=0;
6883
6884 //file header string
6885
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6886 {
6887 new_return(1);
6888 }
6889
6890 //section id
6891
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
6892 {
6893 new_return(2);
6894 }
6895
6896 //section version info
6897
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
6898 {
6899 new_return(3);
6900 }
6901
6902
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
6903 {
6904 new_return(4);
6905 }
6906
6907
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6908 {
6909 12 fake_pack_writing=(writecycle==0);
6910
6911 //section size
6912
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
6913 {
6914 new_return(5);
6915 }
6916
6917 12 writesize=0;
6918
6919 //finally... section data
6920
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(Header->zelda_version,f))
6921 {
6922 new_return(6);
6923 }
6924
6925
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->build,f))
6926 {
6927 new_return(7);
6928 }
6929
6930
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6931 {
6932 new_return(8);
6933 }
6934
6935
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(Header->internal,f))
6936 {
6937 new_return(10);
6938 }
6939
6940
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->quest_number,f))
6941 {
6942 new_return(11);
6943 }
6944
6945
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->version,16,f))
6946 {
6947 new_return(12);
6948 }
6949
6950
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->minver,16,f))
6951 {
6952 new_return(13);
6953 }
6954
6955
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->title,sizeof(Header->title),f))
6956 {
6957 new_return(14);
6958 }
6959
6960
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->author,sizeof(Header->author),f))
6961 {
6962 new_return(15);
6963 }
6964
6965
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->use_keyfile,f))
6966 {
6967 new_return(16);
6968 }
6969
6970
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
6971 {
6972 new_return(17);
6973 }
6974
6975
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
6976 {
6977 new_return(19);
6978 }
6979
6980
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(0,f)) //why are we doing this?
6981 //this is for map count, it seems. -Z
6982 {
6983 new_return(20);
6984 }
6985
6986 12 auto version = getVersion();
6987
6988
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.major,f))
6989 {
6990 new_return(21);
6991 }
6992
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.minor,f))
6993 {
6994 new_return(22);
6995 }
6996
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.patch,f))
6997 {
6998 new_return(23);
6999 }
7000 // Fourth component is deprecated.
7001
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7002 {
7003 new_return(24);
7004 }
7005
7006 // Numerous prerelease stages is deprecated.
7007
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7008 {
7009 new_return(25);
7010 }
7011
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7012 {
7013 new_return(26);
7014 }
7015
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7016 {
7017 new_return(27);
7018 }
7019
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7020 {
7021 new_return(28);
7022 }
7023
7024
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(BUILDTM_YEAR,f))
7025 {
7026 new_return(29);
7027 }
7028
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_MONTH,f))
7029 {
7030 new_return(30);
7031 }
7032
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_DAY,f))
7033 {
7034 new_return(31);
7035 }
7036
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_HOUR,f))
7037 {
7038 new_return(32);
7039 }
7040
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_MINUTE,f))
7041 {
7042 new_return(33);
7043 }
7044
7045
7046
7047 char tempsig[256];
7048 12 memset(tempsig, 0, 256);
7049 12 strcpy(tempsig, DEV_SIGNOFF);
7050
7051
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempsig,256,f))
7052 {
7053 new_return(34);
7054 }
7055
7056 char tempcompilersig[256];
7057 12 memset(tempcompilersig, 0, 256);
7058 12 strcpy(tempcompilersig, COMPILER_NAME);
7059
7060
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempcompilersig,256,f))
7061 {
7062 new_return(35);
7063 }
7064
7065 char tempcompilerversion[256];
7066 12 memset(tempcompilerversion, 0, 256);
7067 #ifdef _MSC_VER
7068 zc_itoa(_MSC_VER,tempcompilerversion,10);
7069 #else
7070 12 strcpy(tempcompilerversion, COMPILER_VERSION);
7071 #endif
7072
7073
7074
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempcompilerversion,256,f))
7075 {
7076 new_return(36);
7077 }
7078
7079
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite("ZQuest Classic",1024,f))
7080 {
7081 new_return(37);
7082 }
7083
7084
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(V_ZC_COMPILERSIG,f))
7085 {
7086 new_return(38);
7087 }
7088 #ifdef _MSC_VER
7089 if(!p_iputl((_MSC_VER / 100),f))
7090 {
7091 new_return(39);
7092 }
7093 #else
7094
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_FIRST,f))
7095 {
7096 new_return(39);
7097 }
7098 #endif
7099
7100
7101
7102 #ifdef _MSC_VER
7103 if(!p_iputl((_MSC_VER % 100),f))
7104 {
7105 new_return(41);
7106 }
7107 #else
7108
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_SECOND,f))
7109 {
7110 new_return(41);
7111 }
7112 #endif
7113
7114 #ifdef _MSC_VER
7115 # if _MSC_VER >= 1400
7116 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7117 {
7118 new_return(40);
7119 }
7120 # else
7121 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7122 {
7123 new_return(40);
7124 }
7125 #endif
7126 #else
7127
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_THIRD,f))
7128 {
7129 new_return(40);
7130 }
7131 #endif
7132
7133 #ifdef _MSC_VER
7134 if(!p_iputl((_MSC_BUILD),f))
7135 {
7136 new_return(42);
7137 }
7138 #else
7139
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_FOURTH,f))
7140 {
7141 new_return(42);
7142 }
7143 #endif
7144
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7145 {
7146 new_return(43);
7147 }
7148
7149 char tempmodulename[1024];
7150 12 memset(tempmodulename, 0, 1024);
7151 12 strcpy(tempmodulename, moduledata.module_name);
7152
7153
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempmodulename,1024,f))
7154 {
7155 new_return(44);
7156 }
7157
7158 char tempdate[256];
7159 12 memset(tempdate, 0, 256);
7160 12 strcpy(tempdate, __DATE__);
7161
7162
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempdate,256,f))
7163 {
7164 new_return(45);
7165 }
7166 char temptime[256];
7167 12 memset(temptime, 0, 256);
7168 12 strcpy(temptime, __TIME__);
7169
7170
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&temptime,256,f))
7171 {
7172 new_return(46);
7173 }
7174
7175
7176 char temptimezone[6];
7177 12 memset(temptimezone, 0, 6);
7178 12 strcpy(temptimezone, __TIMEZONE__);
7179
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&temptimezone,6,f))
7180 {
7181 new_return(47);
7182 }
7183
7184
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7185 {
7186 new_return(48);
7187 }
7188
7189
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(isStableRelease() ? 0 : 1, f))
7190 {
7191 new_return(49);
7192 }
7193
7194
3/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
12 if(!p_putcstr(version.version_string, f))
7195 {
7196 new_return(50);
7197 }
7198
7199
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7200 {
7201 6 section_size=writesize;
7202 6 }
7203 12 }
7204
7205
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7206 {
7207 char ebuf[80];
7208 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7209 jwin_alert("Error: writeheader()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7210 }
7211
7212 6 new_return(0);
7213 }
7214
7215 6 int32_t writerules(PACKFILE *f, zquestheader *Header)
7216 {
7217 //these are here to bypass compiler warnings about unused arguments
7218 6 Header=Header;
7219
7220 6 dword section_id=ID_RULES;
7221 6 dword section_version=V_RULES;
7222 6 dword section_cversion=CV_RULES;
7223 6 dword section_size=0;
7224
7225 //section id
7226
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7227 {
7228 new_return(1);
7229 }
7230
7231 //section version info
7232
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7233 {
7234 new_return(2);
7235 }
7236
7237
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
7238 {
7239 new_return(3);
7240 }
7241
7242
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl(V_COMPATRULE,f))
7243 {
7244 new_return(6);
7245 }
7246
7247
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7248 {
7249 12 fake_pack_writing=(writecycle==0);
7250
7251 //section size
7252
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7253 {
7254 new_return(4);
7255 }
7256
7257 12 writesize=0;
7258
7259 //finally... section data
7260
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7261 {
7262 new_return(5);
7263 }
7264
7265
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7266 {
7267 6 section_size=writesize;
7268 6 }
7269 12 }
7270
7271
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7272 {
7273 char ebuf[80];
7274 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7275 jwin_alert("Error: writerules()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7276 }
7277
7278 6 new_return(0);
7279 }
7280
7281
7282 6 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7283 {
7284 //these are here to bypass compiler warnings about unused arguments
7285 6 Header=Header;
7286
7287 6 dword section_id=ID_DOORS;
7288 6 dword section_version=V_DOORS;
7289 6 dword section_cversion=CV_DOORS;
7290 6 dword section_size=0;
7291
7292 //section id
7293
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7294 {
7295 new_return(1);
7296 }
7297
7298 //section version info
7299
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7300 {
7301 new_return(2);
7302 }
7303
7304
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7305 {
7306 new_return(3);
7307 }
7308
7309
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7310 {
7311 12 fake_pack_writing=(writecycle==0);
7312
7313 //section size
7314
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7315 {
7316 new_return(4);
7317 }
7318
7319 12 writesize=0;
7320
7321 //finally... section data
7322
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(door_combo_set_count,f))
7323 {
7324 new_return(5);
7325 }
7326
7327
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 12 times.
176 for(int32_t i=0; i<door_combo_set_count; i++)
7328 {
7329 //name
7330
1/2
✓ Branch 0 taken 164 times.
✗ Branch 1 not taken.
164 if(!pfwrite(&DoorComboSets[i].name,sizeof(DoorComboSets[0].name),f))
7331 {
7332 new_return(6);
7333 }
7334
7335 //up door
7336
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7337 {
7338
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7339 {
7340
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7341 {
7342 new_return(7);
7343 }
7344 5904 }
7345 1476 }
7346
7347
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7348 {
7349
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7350 {
7351
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7352 {
7353 new_return(8);
7354 }
7355 5904 }
7356 1476 }
7357
7358 //down door
7359
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7360 {
7361
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7362 {
7363
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7364 {
7365 new_return(9);
7366 }
7367 5904 }
7368 1476 }
7369
7370
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7371 {
7372
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7373 {
7374
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7375 {
7376 new_return(10);
7377 }
7378 5904 }
7379 1476 }
7380
7381
7382 //left door
7383
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7384 {
7385
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7386 {
7387
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7388
7389 {
7390 new_return(11);
7391 }
7392 8856 }
7393 1476 }
7394
7395
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7396 {
7397
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7398 {
7399
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7400 {
7401 new_return(12);
7402 }
7403 8856 }
7404 1476 }
7405
7406 //right door
7407
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7408 {
7409
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7410 {
7411
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7412 {
7413 new_return(13);
7414 }
7415 8856 }
7416 1476 }
7417
7418
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7419 {
7420
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7421 {
7422
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7423 {
7424 new_return(14);
7425 }
7426 8856 }
7427 1476 }
7428
7429
7430 //up bomb rubble
7431
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7432 {
7433
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7434 {
7435 new_return(15);
7436 }
7437 328 }
7438
7439
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7440 {
7441
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7442 {
7443 new_return(16);
7444 }
7445 328 }
7446
7447 //down bomb rubble
7448
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7449 {
7450
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7451 {
7452 new_return(17);
7453 }
7454 328 }
7455
7456
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7457 {
7458
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7459 {
7460 new_return(18);
7461 }
7462 328 }
7463
7464 //left bomb rubble
7465
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7466 {
7467
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7468 {
7469 new_return(19);
7470 }
7471 492 }
7472
7473
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7474 {
7475
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7476 {
7477 new_return(20);
7478 }
7479 492 }
7480
7481 //right bomb rubble
7482
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7483 {
7484
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7485 {
7486 new_return(21);
7487 }
7488 492 }
7489
7490
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7491 {
7492
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7493 {
7494 new_return(22);
7495 }
7496 492 }
7497
7498 //walkthrough stuff
7499
2/2
✓ Branch 0 taken 656 times.
✓ Branch 1 taken 164 times.
820 for(int32_t j=0; j<4; j++)
7500 {
7501
1/2
✓ Branch 0 taken 656 times.
✗ Branch 1 not taken.
656 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7502 {
7503 new_return(23);
7504 }
7505 656 }
7506
7507
2/2
✓ Branch 0 taken 656 times.
✓ Branch 1 taken 164 times.
820 for(int32_t j=0; j<4; j++)
7508 {
7509
1/2
✓ Branch 0 taken 656 times.
✗ Branch 1 not taken.
656 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7510 {
7511 new_return(24);
7512 }
7513 656 }
7514
7515 //flags
7516
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7517 {
7518
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].flags[j],f))
7519 {
7520 new_return(25);
7521 }
7522 328 }
7523 164 }
7524
7525
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7526 {
7527 6 section_size=writesize;
7528 6 }
7529 12 }
7530
7531
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7532 {
7533 char ebuf[80];
7534 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7535 jwin_alert("Error: writedoorcombosets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7536 }
7537
7538 6 new_return(0);
7539 }
7540
7541 6 int32_t writedmaps(PACKFILE *f, word version, word build, word start_dmap, word max_dmaps)
7542 {
7543 //these are here to bypass compiler warnings about unused arguments
7544 6 version=version;
7545 6 build=build;
7546
7547 6 word dmap_count=count_dmaps();
7548 6 dword section_id=ID_DMAPS;
7549 6 dword section_version=V_DMAPS;
7550 6 dword section_cversion=CV_DMAPS;
7551 6 dword section_size=0;
7552
7553 //section id
7554
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7555 {
7556 new_return(1);
7557 }
7558
7559 //section version info
7560
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7561 {
7562 new_return(2);
7563 }
7564
7565
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7566 {
7567 new_return(3);
7568 }
7569
7570
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7571 {
7572 12 fake_pack_writing=(writecycle==0);
7573
7574 //section size
7575
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7576 {
7577 new_return(4);
7578 }
7579
7580 12 writesize=0;
7581
7582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 dmap_count=zc_min(dmap_count, max_dmaps);
7583
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7584
7585 //finally... section data
7586
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(dmap_count,f))
7587 {
7588 new_return(5);
7589 }
7590
7591
7592
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7593 {
7594 6144 DMaps[i].validate_subscreens();
7595
7596
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].map,f))
7597 {
7598 new_return(6);
7599 }
7600
7601
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].level,f))
7602 {
7603 new_return(7);
7604 }
7605
7606
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].xoff,f))
7607 {
7608 new_return(8);
7609 }
7610
7611
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].compass,f))
7612 {
7613 new_return(9);
7614 }
7615
7616
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].color,f))
7617 {
7618 new_return(10);
7619 }
7620
7621
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].midi,f))
7622 {
7623 new_return(11);
7624 }
7625
7626
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].cont,f))
7627 {
7628 new_return(12);
7629 }
7630
7631
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].type,f))
7632 {
7633 new_return(13);
7634 }
7635
7636
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t j=0; j<8; j++)
7637 {
7638
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_putc(DMaps[i].grid[j],f))
7639 {
7640 new_return(14);
7641 }
7642 49152 }
7643
7644
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name)-1,f))
7645 {
7646 new_return(15);
7647 }
7648
7649
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putwstr(DMaps[i].title,f))
7650 {
7651 new_return(16);
7652 }
7653
7654
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro)-1,f))
7655 {
7656 new_return(17);
7657 }
7658
7659
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].minimap_1_tile,f))
7660 {
7661 new_return(18);
7662 }
7663
7664
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].minimap_1_cset,f))
7665 {
7666 new_return(19);
7667 }
7668
7669
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].minimap_2_tile,f))
7670 {
7671 new_return(20);
7672 }
7673
7674
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].minimap_2_cset,f))
7675 {
7676 new_return(21);
7677 }
7678
7679
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].largemap_1_tile,f))
7680 {
7681 new_return(22);
7682 }
7683
7684
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].largemap_1_cset,f))
7685 {
7686 new_return(23);
7687 }
7688
7689
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].largemap_2_tile,f))
7690 {
7691 new_return(24);
7692 }
7693
7694
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].largemap_2_cset,f))
7695 {
7696 new_return(25);
7697 }
7698
7699
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic)-1,f))
7700 {
7701 new_return(26);
7702 }
7703
7704
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].tmusictrack,f))
7705 {
7706 new_return(25);
7707 }
7708
7709
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].active_subscreen,f))
7710 {
7711 new_return(26);
7712 }
7713
7714
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].passive_subscreen,f))
7715 {
7716 new_return(27);
7717 }
7718
7719 byte disabled[32];
7720 6144 memset(disabled,0,32);
7721
7722
2/2
✓ Branch 0 taken 1572864 times.
✓ Branch 1 taken 6144 times.
1579008 for(int32_t j=0; j<MAXITEMS; j++)
7723 {
7724
1/2
✓ Branch 0 taken 1572864 times.
✗ Branch 1 not taken.
1572864 if(DMaps[i].disableditems[j])
7725 {
7726 disabled[j/8] |= (1 << (j%8));
7727 }
7728 1572864 }
7729
7730
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(disabled,32,f))
7731 {
7732 new_return(28);
7733 }
7734
7735
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].flags,f))
7736 {
7737 new_return(29);
7738 }
7739
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].sideview,f))
7740 {
7741 new_return(30);
7742 }
7743
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].script,f))
7744 {
7745 new_return(31);
7746 }
7747
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
7748 {
7749
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].initD[q],f))
7750 {
7751 new_return(32);
7752 }
7753
7754 49152 }
7755
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
7756 {
7757
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
7758 {
7759
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if (!p_putc(DMaps[i].initD_label[q][w],f))
7760 {
7761 new_return(33);
7762 }
7763 3194880 }
7764 49152 }
7765
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].active_sub_script,f))
7766 {
7767 new_return(34);
7768 }
7769
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].passive_sub_script,f))
7770 {
7771 new_return(35);
7772 }
7773
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7774 {
7775
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].sub_initD[q],f))
7776 {
7777 new_return(36);
7778 }
7779 49152 }
7780
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7781 {
7782
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for(int32_t w = 0; w < 65; ++w)
7783 {
7784
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
7785 {
7786 new_return(37);
7787 }
7788 3194880 }
7789 49152 }
7790
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].onmap_script,f))
7791 {
7792 new_return(38);
7793 }
7794
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7795 {
7796
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].onmap_initD[q],f))
7797 {
7798 new_return(39);
7799 }
7800 49152 }
7801
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7802 {
7803
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for(int32_t w = 0; w < 65; ++w)
7804 {
7805
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
7806 {
7807 new_return(40);
7808 }
7809 3194880 }
7810 49152 }
7811
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].mirrorDMap,f))
7812 {
7813 new_return(41);
7814 }
7815
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
7816 {
7817 new_return(42);
7818 }
7819
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
7820 {
7821 new_return(43);
7822 }
7823
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
7824 {
7825 new_return(44);
7826 }
7827
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
7828 {
7829 new_return(45);
7830 }
7831
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].overlay_subscreen, f))
7832 new_return(46);
7833
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].intro_string_id, f))
7834 new_return(47);
7835
7836 // Reserved for z3.
7837
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t j=0; j<8; j++)
7838 {
7839
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 393216 times.
442368 for(int32_t k=0; k<8; k++)
7840 {
7841
1/2
✓ Branch 0 taken 393216 times.
✗ Branch 1 not taken.
393216 if(!p_putc(0,f))
7842 {
7843 new_return(48);
7844 }
7845 393216 }
7846 49152 }
7847 6144 }
7848
7849
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7850 {
7851 6 section_size=writesize;
7852 6 }
7853 12 }
7854
7855
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7856 {
7857 char ebuf[80];
7858 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7859 jwin_alert("Error: writedmaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7860 }
7861
7862 6 new_return(0);
7863 }
7864
7865 6 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7866 {
7867 //these are here to bypass compiler warnings about unused arguments
7868 6 Header=Header;
7869
7870 6 dword section_id=ID_COLORS;
7871 6 dword section_version=V_COLORS;
7872 6 dword section_cversion=CV_COLORS;
7873 6 dword section_size = 0;
7874
7875 //section id
7876
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7877 {
7878 new_return(1);
7879 }
7880
7881
7882 //section version info
7883
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7884 {
7885 new_return(2);
7886 }
7887
7888
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7889 {
7890 new_return(3);
7891 }
7892
7893
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7894 {
7895 12 fake_pack_writing=(writecycle==0);
7896
7897 //section size
7898
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7899 {
7900 new_return(4);
7901 }
7902
7903 12 writesize=0;
7904
7905
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.text,f))
7906 {
7907 new_return(5);
7908 }
7909
7910
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.caption,f))
7911 {
7912 new_return(6);
7913 }
7914
7915
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.overw_bg,f))
7916 {
7917 new_return(7);
7918 }
7919
7920
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dngn_bg,f))
7921 {
7922 new_return(8);
7923 }
7924
7925
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dngn_fg,f))
7926 {
7927 new_return(9);
7928 }
7929
7930
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.cave_fg,f))
7931 {
7932 new_return(10);
7933 }
7934
7935
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bs_dk,f))
7936 {
7937 new_return(11);
7938 }
7939
7940
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bs_goal,f))
7941 {
7942 new_return(12);
7943 }
7944
7945
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.compass_lt,f))
7946 {
7947 new_return(13);
7948 }
7949
7950
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.compass_dk,f))
7951 {
7952 new_return(14);
7953 }
7954
7955
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.subscr_bg,f))
7956 {
7957 new_return(15);
7958 }
7959
7960
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triframe_color,f))
7961 {
7962 new_return(16);
7963 }
7964
7965
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.hero_dot,f))
7966 {
7967 new_return(17);
7968 }
7969
7970
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bmap_bg,f))
7971 {
7972 new_return(18);
7973 }
7974
7975
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bmap_fg,f))
7976 {
7977 new_return(19);
7978 }
7979
7980
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triforce_cset,f))
7981 {
7982 new_return(20);
7983 }
7984
7985
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triframe_cset,f))
7986 {
7987 new_return(21);
7988 }
7989
7990
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.overworld_map_cset,f))
7991 {
7992 new_return(22);
7993 }
7994
7995
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
7996 {
7997 new_return(23);
7998 }
7999
8000
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.blueframe_cset,f))
8001 {
8002 new_return(24);
8003 }
8004
8005
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.HCpieces_cset,f))
8006 {
8007 new_return(31);
8008 }
8009
8010
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.subscr_shadow,f))
8011 {
8012 new_return(32);
8013 }
8014
8015
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.msgtext,f))
8016 {
8017 new_return(33);
8018 }
8019
8020
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.triforce_tile,f))
8021 {
8022 new_return(34);
8023 }
8024
8025
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.triframe_tile,f))
8026 {
8027 new_return(35);
8028 }
8029
8030
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
8031 {
8032 new_return(36);
8033 }
8034
8035
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
8036 {
8037 new_return(37);
8038 }
8039
8040
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.blueframe_tile,f))
8041 {
8042 new_return(38);
8043 }
8044
8045
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
8046 {
8047 new_return(39);
8048 }
8049
8050
8051
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8052 {
8053 6 section_size=writesize;
8054 6 }
8055 12 }
8056
8057
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8058 {
8059 char ebuf[80];
8060 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8061 jwin_alert("Error: writemisccolors()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8062 }
8063
8064 6 new_return(0);
8065 }
8066
8067 6 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
8068 {
8069 //these are here to bypass compiler warnings about unused arguments
8070 6 Header=Header;
8071
8072 6 dword section_id=ID_ICONS;
8073 6 dword section_version=V_ICONS;
8074 6 dword section_cversion=CV_ICONS;
8075 6 dword section_size = 0;
8076
8077 //section id
8078
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8079 {
8080 new_return(1);
8081 }
8082
8083 //section version info
8084
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8085 {
8086 new_return(2);
8087 }
8088
8089
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8090 {
8091 new_return(3);
8092 }
8093
8094
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8095 {
8096 12 fake_pack_writing=(writecycle==0);
8097
8098 //section size
8099
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8100 {
8101 new_return(4);
8102 }
8103
8104 12 writesize=0;
8105
8106
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
8107 {
8108
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(QMisc.icons[i],f))
8109 {
8110 new_return(5);
8111 }
8112 48 }
8113
8114
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8115 {
8116 6 section_size=writesize;
8117 6 }
8118 12 }
8119
8120
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8121 {
8122 char ebuf[80];
8123 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8124 jwin_alert("Error: writegameicons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8125 }
8126
8127 6 new_return(0);
8128 }
8129
8130 6 int32_t writemisc(PACKFILE *f, zquestheader *Header)
8131 {
8132 //these are here to bypass compiler warnings about unused arguments
8133 6 Header=Header;
8134
8135 6 dword section_id=ID_MISC;
8136 6 dword section_version=V_MISC;
8137 6 dword section_cversion=CV_MISC;
8138 6 word shops=count_shops(&QMisc);
8139 6 word infos=count_infos(&QMisc);
8140 6 word warprings=count_warprings(&QMisc);
8141 6 word triforces=8;
8142 6 dword section_size = 0;
8143
8144 //section id
8145
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8146 {
8147 new_return(1);
8148 }
8149
8150
8151 //section version info
8152
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8153 {
8154 new_return(2);
8155 }
8156
8157
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8158 {
8159 new_return(3);
8160 }
8161
8162
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8163 {
8164 12 fake_pack_writing=(writecycle==0);
8165
8166 //section size
8167
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8168 {
8169 new_return(4);
8170 }
8171
8172 12 writesize=0;
8173
8174 //shops
8175
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(shops,f))
8176 {
8177 new_return(5);
8178 }
8179
8180
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<shops; i++)
8181 {
8182
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
8183 {
8184 new_return(6);
8185 }
8186
8187
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8188 {
8189
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(QMisc.shop[i].item[j],f))
8190 {
8191 new_return(7);
8192 }
8193 384 }
8194
8195
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8196 {
8197
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.shop[i].price[j],f))
8198 {
8199 new_return(8);
8200 }
8201 384 }
8202
8203
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8204 {
8205
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8206 {
8207 new_return(9);
8208 }
8209 384 }
8210 128 }
8211
8212 //infos
8213
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(infos,f))
8214 {
8215 new_return(10);
8216 }
8217
8218
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<infos; i++)
8219 {
8220
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8221 {
8222 new_return(11);
8223 }
8224
8225
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8226 {
8227
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.info[i].str[j],f))
8228 {
8229 new_return(12);
8230 }
8231 384 }
8232
8233
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8234 {
8235
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.info[i].price[j],f))
8236 {
8237 new_return(13);
8238 }
8239 384 }
8240 128 }
8241
8242 //warp rings
8243
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(warprings,f))
8244 {
8245 new_return(14);
8246 }
8247
8248
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 12 times.
156 for(int32_t i=0; i<warprings; i++)
8249 {
8250
2/2
✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 144 times.
1440 for(int32_t j=0; j<9; j++)
8251 {
8252
1/2
✓ Branch 0 taken 1296 times.
✗ Branch 1 not taken.
1296 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8253 {
8254 new_return(15);
8255 }
8256 1296 }
8257
8258
2/2
✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 144 times.
1440 for(int32_t j=0; j<9; j++)
8259 {
8260
1/2
✓ Branch 0 taken 1296 times.
✗ Branch 1 not taken.
1296 if(!p_putc(QMisc.warp[i].scr[j],f))
8261 {
8262 new_return(16);
8263 }
8264 1296 }
8265
8266
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.warp[i].size,f))
8267 {
8268 new_return(17);
8269 }
8270 144 }
8271
8272 //triforce pieces
8273
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<triforces; i++)
8274 {
8275
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(!p_putc(QMisc.triforce[i],f))
8276 {
8277 new_return(18);
8278 }
8279 96 }
8280
8281 //end string
8282
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(QMisc.endstring,f))
8283 {
8284 new_return(19);
8285 }
8286
8287 //V_MISC >= 8
8288
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<shops; i++)
8289 {
8290
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8291 {
8292
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.shop[i].str[j],f))
8293 {
8294 new_return(20);
8295 }
8296 384 }
8297 128 }
8298 //V_MISC >= 9
8299
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for ( int32_t q = 0; q < 32; q++ )
8300 {
8301
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputl(QMisc.questmisc[q],f))
8302 new_return(21);
8303 384 }
8304
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for ( int32_t q = 0; q < 32; q++ )
8305 {
8306
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 384 times.
49536 for ( int32_t j = 0; j < 128; j++ )
8307
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_putc(0,f))
8308 new_return(22);
8309 384 }
8310 //V_MISC >= 11
8311
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8312 new_return(23);
8313
8314 //V_MISC >= 12
8315
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t q = 0; q < sprMAX; ++q)
8316 {
8317
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(QMisc.sprites[q],f))
8318 new_return(24);
8319 3072 }
8320
8321 //V_MISC >= 13
8322
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 12 times.
780 for(size_t q = 0; q < 64; ++q)
8323 {
8324 768 bottletype* bt = &(QMisc.bottle_types[q]);
8325
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!pfwrite(bt->name, 32, f))
8326 new_return(25);
8327
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 768 times.
3072 for(size_t j = 0; j < 3; ++j)
8328 {
8329
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 if (!p_putc(bt->counter[j], f))
8330 new_return(25);
8331
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 if (!p_iputw(bt->amount[j], f))
8332 new_return(25);
8333 2304 }
8334
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!p_putc(bt->flags, f))
8335 new_return(25);
8336
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!p_putc(bt->next_type, f))
8337 new_return(25);
8338 768 }
8339
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(size_t q = 0; q < 256; ++q)
8340 {
8341 3072 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8342
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if (!pfwrite(bst->name, 32, f))
8343 new_return(26);
8344
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 3072 times.
12288 for(size_t j = 0; j < 3; ++j)
8345 {
8346
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(bst->fill[j], f))
8347 new_return(26);
8348
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputw(bst->comb[j], f))
8349 new_return(26);
8350
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(bst->cset[j], f))
8351 new_return(26);
8352
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputw(bst->price[j], f))
8353 new_return(26);
8354
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if (!p_iputw(bst->str[j], f))
8355 new_return(26);
8356 9216 }
8357 3072 }
8358
8359 //V_MISC >= 14
8360
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t q = 0; q < sfxMAX; ++q)
8361 {
8362
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(QMisc.miscsfx[q],f))
8363 new_return(27);
8364 3072 }
8365
8366
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8367 {
8368 6 section_size=writesize;
8369 6 }
8370 12 }
8371
8372
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8373 {
8374 char ebuf[80];
8375 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8376 jwin_alert("Error: writemisc()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8377 }
8378
8379 6 new_return(0);
8380 }
8381
8382 6 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8383 {
8384 //these are here to bypass compiler warnings about unused arguments
8385 6 Header=Header;
8386
8387 6 dword section_id=ID_ITEMS;
8388 6 dword section_version=V_ITEMS;
8389 6 dword section_cversion=CV_ITEMS;
8390 // dword section_size=0;
8391 6 dword section_size = 0;
8392
8393 //section id
8394
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8395 {
8396 new_return(1);
8397 }
8398
8399 //section version info
8400
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8401 {
8402 new_return(2);
8403 }
8404
8405
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8406 {
8407 new_return(3);
8408 }
8409
8410
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8411 {
8412 12 fake_pack_writing=(writecycle==0);
8413
8414 //section size
8415
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8416 {
8417 new_return(4);
8418 }
8419
8420 12 writesize=0;
8421
8422 //finally... section data
8423
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(MAXITEMS,f))
8424 {
8425 new_return(5);
8426 }
8427
8428
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
8429 {
8430
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!pfwrite(item_string[i], 64, f))
8431 {
8432 new_return(5);
8433 }
8434 3072 }
8435
8436
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
8437 {
8438
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tile,f))
8439 {
8440 new_return(6);
8441 }
8442
8443
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].misc_flags,f))
8444 {
8445 new_return(7);
8446 }
8447
8448
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].csets,f))
8449 {
8450 new_return(8);
8451 }
8452
8453
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].frames,f))
8454 {
8455 new_return(9);
8456 }
8457
8458
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].speed,f))
8459 {
8460 new_return(10);
8461 }
8462
8463
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].delay,f))
8464 {
8465 new_return(11);
8466 }
8467
8468
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].ltm,f))
8469 {
8470 new_return(12);
8471 }
8472
8473
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].family,f))
8474 {
8475 new_return(13);
8476 }
8477
8478
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].fam_type,f))
8479 {
8480 new_return(14);
8481 }
8482
8483
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].power,f))
8484 {
8485 new_return(14);
8486 }
8487
8488
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].flags,f))
8489 {
8490 new_return(15);
8491 }
8492
8493
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].script,f))
8494 {
8495 new_return(16);
8496 }
8497
8498
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].count,f))
8499 {
8500 new_return(17);
8501 }
8502
8503
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].amount,f))
8504 {
8505 new_return(18);
8506 }
8507
8508
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].collect_script,f))
8509 {
8510 new_return(19);
8511 }
8512
8513
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].setmax,f))
8514 {
8515 new_return(21);
8516 }
8517
8518
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].max,f))
8519 {
8520 new_return(22);
8521 }
8522
8523
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].playsound,f))
8524 {
8525 new_return(23);
8526 }
8527
8528
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for(int32_t j=0; j<8; j++)
8529 {
8530
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].initiald[j],f))
8531 {
8532 new_return(24);
8533 }
8534 24576 }
8535
8536
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(int32_t j=0; j<2; j++)
8537 {
8538
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].initiala[j],f))
8539 {
8540 new_return(25);
8541 }
8542 6144 }
8543
8544
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn,f))
8545 {
8546 new_return(26);
8547 }
8548
8549
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn2,f))
8550 {
8551 new_return(27);
8552 }
8553
8554
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn3,f))
8555 {
8556 new_return(28);
8557 }
8558
8559
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn4,f))
8560 {
8561 new_return(29);
8562 }
8563
8564
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn5,f))
8565 {
8566 new_return(30);
8567 }
8568
8569
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn6,f))
8570 {
8571 new_return(31);
8572 }
8573
8574
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn7,f))
8575 {
8576 new_return(32);
8577 }
8578
8579
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn8,f))
8580 {
8581 new_return(33);
8582 }
8583
8584
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn9,f))
8585 {
8586 new_return(34);
8587 }
8588
8589
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn10,f))
8590 {
8591 new_return(35);
8592 }
8593
8594
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8595 {
8596 new_return(36);
8597 }
8598
8599
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc1,f))
8600 {
8601 new_return(37);
8602 }
8603
8604
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc2,f))
8605 {
8606 new_return(38);
8607 }
8608
8609
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8610 {
8611
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8612 {
8613 new_return(39);
8614 }
8615 6144 }
8616
8617
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc3,f))
8618 {
8619 new_return(40);
8620 }
8621
8622
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc4,f))
8623 {
8624 new_return(41);
8625 }
8626
8627
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc5,f))
8628 {
8629 new_return(42);
8630 }
8631
8632
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc6,f))
8633 {
8634 new_return(43);
8635 }
8636
8637
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc7,f))
8638 {
8639 new_return(44);
8640 }
8641
8642
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc8,f))
8643 {
8644 new_return(45);
8645 }
8646
8647
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc9,f))
8648 {
8649 new_return(46);
8650 }
8651
8652
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc10,f))
8653 {
8654 new_return(47);
8655 }
8656
8657
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usesound,f))
8658 {
8659 new_return(48);
8660 }
8661
8662
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usesound2,f))
8663 {
8664 new_return(48);
8665 }
8666
8667 //New itemdata vars -Z
8668 //! version 27
8669
8670
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].useweapon,f))
8671 {
8672 new_return(49);
8673 }
8674
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usedefence,f))
8675 {
8676 new_return(50);
8677 }
8678
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weaprange,f))
8679 {
8680 new_return(51);
8681 }
8682
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weapduration,f))
8683 {
8684 new_return(52);
8685 }
8686
2/2
✓ Branch 0 taken 30720 times.
✓ Branch 1 taken 3072 times.
33792 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8687
1/2
✓ Branch 0 taken 30720 times.
✗ Branch 1 not taken.
30720 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8688 {
8689 new_return(53);
8690 }
8691 30720 }
8692 //version 28
8693
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].duplicates,f))
8694 {
8695 new_return(54);
8696 }
8697
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for ( int32_t q = 0; q < INITIAL_D; q++ )
8698 {
8699
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].weap_initiald[q],f))
8700 {
8701 new_return(55);
8702 }
8703 24576 }
8704
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for ( int32_t q = 0; q < INITIAL_A; q++ )
8705 {
8706
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].weap_initiala[q],f))
8707 {
8708 new_return(56);
8709 }
8710 6144 }
8711
8712
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].drawlayer,f))
8713 {
8714 new_return(57);
8715 }
8716
8717
8718
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hxofs,f))
8719 {
8720 new_return(58);
8721 }
8722
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hyofs,f))
8723 {
8724 new_return(59);
8725 }
8726
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hxsz,f))
8727 {
8728 new_return(60);
8729 }
8730
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hysz,f))
8731 {
8732 new_return(61);
8733 }
8734
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hzsz,f))
8735 {
8736 new_return(62);
8737 }
8738
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].xofs,f))
8739 {
8740 new_return(63);
8741 }
8742
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].yofs,f))
8743 {
8744 new_return(64);
8745 }
8746
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hxofs,f))
8747 {
8748 new_return(65);
8749 }
8750
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hyofs,f))
8751 {
8752 new_return(66);
8753 }
8754
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hxsz,f))
8755 {
8756 new_return(67);
8757 }
8758
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hysz,f))
8759 {
8760 new_return(68);
8761 }
8762
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hzsz,f))
8763 {
8764 new_return(69);
8765 }
8766
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_xofs,f))
8767 {
8768 new_return(70);
8769 }
8770
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_yofs,f))
8771 {
8772 new_return(71);
8773 }
8774
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].weaponscript,f))
8775 {
8776 new_return(72);
8777 }
8778
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8779 {
8780 new_return(73);
8781 }
8782
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8783 {
8784
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8785 {
8786 new_return(74);
8787 }
8788 6144 }
8789
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8790 {
8791 new_return(75);
8792 }
8793
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tilew,f))
8794 {
8795 new_return(76);
8796 }
8797
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tileh,f))
8798 {
8799 new_return(77);
8800 }
8801
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weapoverrideFLAGS,f))
8802 {
8803 new_return(78);
8804 }
8805
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_tilew,f))
8806 {
8807 new_return(79);
8808 }
8809
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_tileh,f))
8810 {
8811 new_return(80);
8812 }
8813
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].pickup,f))
8814 {
8815 new_return(81);
8816 }
8817
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].pstring,f))
8818 {
8819 new_return(82);
8820 }
8821
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8822 {
8823 new_return(83);
8824 }
8825
8826
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8827 {
8828
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8829 {
8830 new_return(84);
8831 }
8832 6144 }
8833
8834 //InitD[] labels
8835
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for ( int32_t q = 0; q < 8; q++ )
8836 {
8837
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8838 {
8839
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8840 {
8841 new_return(85);
8842 }
8843 1597440 }
8844
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8845 {
8846
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].weapon_initD_label[q][w],f))
8847 {
8848 new_return(86);
8849 }
8850 1597440 }
8851
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8852 {
8853
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8854 {
8855 new_return(87);
8856 }
8857 1597440 }
8858
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8859 {
8860 new_return(88);
8861 }
8862 24576 }
8863
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for ( int32_t q = 0; q < 2; q++ )
8864 {
8865
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].sprite_initiala[q],f))
8866 {
8867 new_return(89);
8868 }
8869
8870 6144 }
8871
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].sprite_script,f))
8872 {
8873 new_return(90);
8874 }
8875
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].pickupflag,f))
8876 {
8877 new_return(91);
8878 }
8879
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 std::string dispname(itemsbuf[i].display_name);
8880
2/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3072 times.
✗ Branch 3 not taken.
3072 if(!p_putcstr(dispname,f))
8881 new_return(92);
8882
2/2
✓ Branch 0 taken 15360 times.
✓ Branch 1 taken 3072 times.
18432 for(int q = 0; q < WPNSPR_MAX; ++q)
8883 {
8884
2/4
✓ Branch 0 taken 15360 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15360 times.
✗ Branch 3 not taken.
15360 if(!p_putc(itemsbuf[i].burnsprs[q], f))
8885 new_return(93);
8886
2/4
✓ Branch 0 taken 15360 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15360 times.
✗ Branch 3 not taken.
15360 if(!p_putc(itemsbuf[i].light_rads[q], f))
8887 new_return(94);
8888 15360 }
8889 3072 }
8890
8891
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8892 {
8893 6 section_size=writesize;
8894 6 }
8895 12 }
8896
8897
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8898 {
8899 char ebuf[80];
8900 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8901 jwin_alert("Error: writeitems()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8902 }
8903
8904 6 new_return(0);
8905 }
8906
8907 6 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8908 {
8909 //these are here to bypass compiler warnings about unused arguments
8910 6 Header=Header;
8911
8912 6 dword section_id=ID_WEAPONS;
8913 6 dword section_version=V_WEAPONS;
8914 6 dword section_cversion=CV_WEAPONS;
8915 6 dword section_size = 0;
8916
8917 //section id
8918
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8919 {
8920 new_return(1);
8921 }
8922
8923 //section version info
8924
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8925 {
8926 new_return(2);
8927 }
8928
8929
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8930 {
8931 new_return(3);
8932 }
8933
8934
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8935 {
8936 12 fake_pack_writing=(writecycle==0);
8937
8938 //section size
8939
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8940 {
8941 new_return(4);
8942 }
8943
8944 12 writesize=0;
8945
8946 //finally... section data
8947
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(MAXWPNS,f))
8948 {
8949 new_return(5);
8950 }
8951
8952
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
8953 {
8954
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!pfwrite((char *)weapon_string[i], 64, f))
8955 {
8956 new_return(5);
8957 }
8958 3072 }
8959
8960
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
8961 {
8962
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].misc,f))
8963 {
8964 new_return(7);
8965 }
8966
8967
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].csets,f))
8968 {
8969 new_return(8);
8970 }
8971
8972
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].frames,f))
8973 {
8974 new_return(9);
8975 }
8976
8977
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].speed,f))
8978 {
8979 new_return(10);
8980 }
8981
8982
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].type,f))
8983 {
8984 new_return(11);
8985 }
8986
8987
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(wpnsbuf[i].script,f))
8988 {
8989 new_return(12);
8990 }
8991
8992
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(wpnsbuf[i].tile,f))
8993 {
8994 new_return(12);
8995 }
8996 3072 }
8997
8998
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8999 {
9000 6 section_size=writesize;
9001 6 }
9002 12 }
9003
9004
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
9005 {
9006 char ebuf[80];
9007 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9008 jwin_alert("Error: writeweapons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9009 }
9010
9011 6 new_return(0);
9012 }
9013
9014 4080 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
9015 {
9016
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4080 times.
4080 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9017 return qe_invalid;
9018
9019 4080 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9020 4080 bool is_0x80_screen = j >= 0x80;
9021
9022
1/2
✓ Branch 0 taken 4080 times.
✗ Branch 1 not taken.
4080 if(!p_putc(screen.valid,f))
9023 return qe_invalid;
9024
2/2
✓ Branch 0 taken 2082 times.
✓ Branch 1 taken 1998 times.
4080 if(!(screen.valid & mVALID))
9025 1998 return qe_OK;
9026 //Calculate what needs writing
9027 2082 uint32_t scr_has_flags = 0;
9028
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2080 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2082 if(screen.guytile || screen.guy || screen.roomflags || screen.str
9029
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
9030 2082 scr_has_flags |= SCRHAS_ROOMDATA;
9031
7/8
✓ Branch 0 taken 1800 times.
✓ Branch 1 taken 282 times.
✓ Branch 2 taken 120 times.
✓ Branch 3 taken 1680 times.
✓ Branch 4 taken 112 times.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 112 times.
2082 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
9032 290 scr_has_flags |= SCRHAS_ITEM;
9033
3/4
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2064 times.
2082 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
9034 18 scr_has_flags |= SCRHAS_TWARP;
9035
2/2
✓ Branch 0 taken 1896 times.
✓ Branch 1 taken 7754 times.
9650 else for(auto q = 0; q < 4; ++q)
9036 {
9037
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7586 times.
15340 if(screen.tilewarptype[q]
9038
2/2
✓ Branch 0 taken 7588 times.
✓ Branch 1 taken 166 times.
7754 || screen.tilewarpdmap[q]
9039
2/2
✓ Branch 0 taken 7586 times.
✓ Branch 1 taken 2 times.
7588 || screen.tilewarpscr[q])
9040 {
9041 168 scr_has_flags |= SCRHAS_TWARP;
9042 168 break;
9043 }
9044 7586 }
9045
3/4
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2076 times.
2082 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
9046
2/2
✓ Branch 0 taken 2076 times.
✓ Branch 1 taken 2 times.
2078 || screen.sidewarpoverlayflags)
9047 6 scr_has_flags |= SCRHAS_SWARP;
9048
2/2
✓ Branch 0 taken 636 times.
✓ Branch 1 taken 3984 times.
4620 else for(auto q = 0; q < 4; ++q)
9049 {
9050
2/2
✓ Branch 0 taken 2544 times.
✓ Branch 1 taken 8 times.
6536 if(screen.sidewarptype[q] != wtSCROLL
9051
2/2
✓ Branch 0 taken 2560 times.
✓ Branch 1 taken 1424 times.
3984 || screen.sidewarpdmap[q]
9052
2/2
✓ Branch 0 taken 2552 times.
✓ Branch 1 taken 8 times.
2560 || screen.sidewarpscr[q])
9053 {
9054 1440 scr_has_flags |= SCRHAS_SWARP;
9055 1440 break;
9056 }
9057 2544 }
9058
3/4
✓ Branch 0 taken 2038 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2038 times.
2082 if(screen.warparrivalx || screen.warparrivaly)
9059 44 scr_has_flags |= SCRHAS_WARPRET;
9060
2/2
✓ Branch 0 taken 1450 times.
✓ Branch 1 taken 6388 times.
7838 else for(auto q = 0; q < 4; ++q)
9061 {
9062
3/4
✓ Branch 0 taken 5800 times.
✓ Branch 1 taken 588 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5800 times.
6388 if(screen.warpreturnx[q] || screen.warpreturny[q])
9063 {
9064 588 scr_has_flags |= SCRHAS_WARPRET;
9065 588 break;
9066 }
9067 5800 }
9068
9069
2/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2082 times.
2082 if(screen.hidelayers || screen.hidescriptlayers)
9070 scr_has_flags |= SCRHAS_LAYERS;
9071
2/2
✓ Branch 0 taken 1890 times.
✓ Branch 1 taken 11548 times.
13438 else for(auto q = 0; q < 6; ++q)
9072 {
9073
4/4
✓ Branch 0 taken 11366 times.
✓ Branch 1 taken 182 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 11356 times.
11548 if(screen.layermap[q] || screen.layerscreen[q]
9074
1/2
✓ Branch 0 taken 11366 times.
✗ Branch 1 not taken.
11366 || screen.layeropacity[q]!=255)
9075 {
9076 192 scr_has_flags |= SCRHAS_LAYERS;
9077 192 break;
9078 }
9079 11356 }
9080
9081
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
2082 if(screen.exitdir)
9082 4 scr_has_flags |= SCRHAS_MAZE;
9083
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 8312 times.
10390 else for(auto q = 0; q < 4; ++q)
9084 {
9085
1/2
✓ Branch 0 taken 8312 times.
✗ Branch 1 not taken.
8312 if(screen.path[q])
9086 {
9087 scr_has_flags |= SCRHAS_MAZE;
9088 break;
9089 }
9090 8312 }
9091
9092
4/4
✓ Branch 0 taken 1848 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 238 times.
✓ Branch 3 taken 752 times.
3072 if(screen.door_combo_set || screen.stairx
9093
3/4
✓ Branch 0 taken 1820 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 1820 times.
✗ Branch 3 not taken.
1848 || screen.stairy || screen.undercombo
9094
2/2
✓ Branch 0 taken 990 times.
✓ Branch 1 taken 830 times.
1820 || screen.undercset)
9095 1330 scr_has_flags |= SCRHAS_D_S_U;
9096
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 812 times.
832 else for(auto q = 0; q < 4; ++q)
9097 {
9098
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 732 times.
812 if(screen.door[q] != dNONE)
9099 {
9100 732 scr_has_flags |= SCRHAS_D_S_U;
9101 732 break;
9102 }
9103 80 }
9104
9105
2/2
✓ Branch 0 taken 1822 times.
✓ Branch 1 taken 260 times.
3540 if(screen.flags || screen.flags2
9106
4/4
✓ Branch 0 taken 1736 times.
✓ Branch 1 taken 86 times.
✓ Branch 2 taken 1702 times.
✓ Branch 3 taken 34 times.
1822 || screen.flags3 || screen.flags4
9107
4/4
✓ Branch 0 taken 1688 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 1674 times.
✓ Branch 3 taken 14 times.
1702 || screen.flags5 || screen.flags6
9108
4/4
✓ Branch 0 taken 1466 times.
✓ Branch 1 taken 208 times.
✓ Branch 2 taken 1458 times.
✓ Branch 3 taken 8 times.
1674 || screen.flags7 || screen.flags8
9109
2/4
✓ Branch 0 taken 1458 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1458 times.
✗ Branch 3 not taken.
1458 || screen.flags9 || screen.flags10
9110
1/2
✓ Branch 0 taken 1458 times.
✗ Branch 1 not taken.
1458 || screen.enemyflags)
9111 2082 scr_has_flags |= SCRHAS_FLAGS;
9112
9113
2/2
✓ Branch 0 taken 2032 times.
✓ Branch 1 taken 50 times.
2082 if(screen.pattern)
9114 50 scr_has_flags |= SCRHAS_ENEMY;
9115
2/2
✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 14560 times.
15952 else for(auto q = 0; q < 10; ++q)
9116 {
9117
2/2
✓ Branch 0 taken 13920 times.
✓ Branch 1 taken 640 times.
14560 if(screen.enemy[q])
9118 {
9119 640 scr_has_flags |= SCRHAS_ENEMY;
9120 640 break;
9121 }
9122 13920 }
9123
9124
2/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2076 times.
4158 if(screen.noreset || screen.nocarry
9125
3/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2076 times.
✓ Branch 3 taken 6 times.
2082 || screen.nextmap || screen.nextscr)
9126 6 scr_has_flags |= SCRHAS_CARRY;
9127
9128
3/4
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2064 times.
2082 if(screen.script || screen.preloadscript)
9129 18 scr_has_flags |= SCRHAS_SCRIPT;
9130
2/2
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 16512 times.
18576 else for(auto q = 0; q < 8; ++q)
9131 {
9132
1/2
✓ Branch 0 taken 16512 times.
✗ Branch 1 not taken.
16512 if(screen.screeninitd[q])
9133 {
9134 scr_has_flags |= SCRHAS_SCRIPT;
9135 break;
9136 }
9137 16512 }
9138
9139
2/2
✓ Branch 0 taken 2082 times.
✓ Branch 1 taken 20820 times.
22902 for(auto q = 0; q < 10; ++q)
9140 {
9141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20820 times.
41640 if(screen.npcstrings[q]
9142
1/2
✓ Branch 0 taken 20820 times.
✗ Branch 1 not taken.
20820 || screen.new_items[q]
9143
1/2
✓ Branch 0 taken 20820 times.
✗ Branch 1 not taken.
20820 || screen.new_item_x[q]
9144
1/2
✓ Branch 0 taken 20820 times.
✗ Branch 1 not taken.
20820 || screen.new_item_y[q])
9145 {
9146 scr_has_flags |= SCRHAS_UNUSED;
9147 break;
9148 }
9149 20820 }
9150
9151
2/2
✓ Branch 0 taken 758 times.
✓ Branch 1 taken 99352 times.
100110 for(auto q = 0; q < 128; ++q)
9152 {
9153
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 98028 times.
197380 if(screen.secretcombo[q]
9154
2/2
✓ Branch 0 taken 98030 times.
✓ Branch 1 taken 1322 times.
99352 || screen.secretcset[q]
9155
2/2
✓ Branch 0 taken 98028 times.
✓ Branch 1 taken 2 times.
98030 || screen.secretflag[q])
9156 {
9157 1324 scr_has_flags |= SCRHAS_SECRETS;
9158 1324 break;
9159 }
9160 98028 }
9161
9162
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 40228 times.
40400 for(auto q = 0; q < 176; ++q)
9163 {
9164
4/4
✓ Branch 0 taken 38408 times.
✓ Branch 1 taken 1820 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 38318 times.
40228 if(screen.data[q] || screen.cset[q]
9165
2/2
✓ Branch 0 taken 38320 times.
✓ Branch 1 taken 88 times.
38408 || screen.sflag[q])
9166 {
9167 1910 scr_has_flags |= SCRHAS_COMBOFLAG;
9168 1910 break;
9169 }
9170 38318 }
9171
9172
2/2
✓ Branch 0 taken 786 times.
✓ Branch 1 taken 1296 times.
2082 if(screen.color || screen.csensitive != 1
9173
3/4
✓ Branch 0 taken 786 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 752 times.
✓ Branch 3 taken 34 times.
786 || screen.oceansfx || screen.bosssfx
9174
2/4
✓ Branch 0 taken 752 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 752 times.
752 || screen.secretsfx || screen.holdupsfx
9175 || screen.timedwarptics || screen.screen_midi != -1
9176 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9177 2082 scr_has_flags |= SCRHAS_MISC;
9178
9179
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputl(scr_has_flags,f))
9180 return qe_invalid;
9181
9182 //Write stuff
9183
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(scr_has_flags & SCRHAS_ROOMDATA)
9184 {
9185
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.guy,f))
9186 return qe_invalid;
9187
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputl(screen.guytile,f))
9188 return qe_invalid;
9189
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.guycs,f))
9190 return qe_invalid;
9191
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.roomflags,f))
9192 return qe_invalid;
9193
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.str,f))
9194 return qe_invalid;
9195
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.room,f))
9196 return qe_invalid;
9197
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.catchall,f))
9198 return qe_invalid;
9199 2082 }
9200
2/2
✓ Branch 0 taken 1792 times.
✓ Branch 1 taken 290 times.
2082 if(scr_has_flags & SCRHAS_ITEM)
9201 {
9202
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.item,f))
9203 return qe_invalid;
9204
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.hasitem,f))
9205 return qe_invalid;
9206
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.itemx,f))
9207 return qe_invalid;
9208
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.itemy,f))
9209 return qe_invalid;
9210 290 }
9211
2/2
✓ Branch 0 taken 582 times.
✓ Branch 1 taken 1500 times.
2082 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9212 {
9213
1/2
✓ Branch 0 taken 1500 times.
✗ Branch 1 not taken.
1500 if(!p_iputw(screen.warpreturnc,f))
9214 return qe_invalid;
9215 1500 }
9216
2/2
✓ Branch 0 taken 1896 times.
✓ Branch 1 taken 186 times.
2082 if(scr_has_flags & SCRHAS_TWARP)
9217 {
9218
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9219 {
9220
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_putc(screen.tilewarptype[k],f))
9221 return qe_invalid;
9222 744 }
9223
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9224 {
9225
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_iputw(screen.tilewarpdmap[k],f))
9226 return qe_invalid;
9227 744 }
9228
9229
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9230 {
9231
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_putc(screen.tilewarpscr[k],f))
9232 return qe_invalid;
9233 744 }
9234
9235
1/2
✓ Branch 0 taken 186 times.
✗ Branch 1 not taken.
186 if(!p_putc(screen.tilewarpoverlayflags,f))
9236 return qe_invalid;
9237 186 }
9238
2/2
✓ Branch 0 taken 636 times.
✓ Branch 1 taken 1446 times.
2082 if(scr_has_flags & SCRHAS_SWARP)
9239 {
9240
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9241 {
9242
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_putc(screen.sidewarptype[k],f))
9243 return qe_invalid;
9244 5784 }
9245
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9246 {
9247
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_iputw(screen.sidewarpdmap[k],f))
9248 return qe_invalid;
9249 5784 }
9250
9251
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9252 {
9253
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_putc(screen.sidewarpscr[k],f))
9254 return qe_invalid;
9255 5784 }
9256
9257
1/2
✓ Branch 0 taken 1446 times.
✗ Branch 1 not taken.
1446 if(!p_putc(screen.sidewarpoverlayflags,f))
9258 return qe_invalid;
9259
1/2
✓ Branch 0 taken 1446 times.
✗ Branch 1 not taken.
1446 if(!p_putc(screen.sidewarpindex,f))
9260 return qe_invalid;
9261 1446 }
9262
2/2
✓ Branch 0 taken 1450 times.
✓ Branch 1 taken 632 times.
2082 if(scr_has_flags & SCRHAS_WARPRET)
9263 {
9264
2/2
✓ Branch 0 taken 2528 times.
✓ Branch 1 taken 632 times.
3160 for(int32_t k=0; k<4; k++)
9265 {
9266
1/2
✓ Branch 0 taken 2528 times.
✗ Branch 1 not taken.
2528 if(!p_putc(screen.warpreturnx[k],f))
9267 return qe_invalid;
9268 2528 }
9269
2/2
✓ Branch 0 taken 2528 times.
✓ Branch 1 taken 632 times.
3160 for(int32_t k=0; k<4; k++)
9270 {
9271
1/2
✓ Branch 0 taken 2528 times.
✗ Branch 1 not taken.
2528 if(!p_putc(screen.warpreturny[k],f))
9272 return qe_invalid;
9273 2528 }
9274
1/2
✓ Branch 0 taken 632 times.
✗ Branch 1 not taken.
632 if(!p_putc(screen.warparrivalx,f))
9275 return qe_invalid;
9276
1/2
✓ Branch 0 taken 632 times.
✗ Branch 1 not taken.
632 if(!p_putc(screen.warparrivaly,f))
9277 return qe_invalid;
9278 632 }
9279
2/2
✓ Branch 0 taken 1890 times.
✓ Branch 1 taken 192 times.
2082 if(scr_has_flags & SCRHAS_LAYERS)
9280 {
9281
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9282 {
9283
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layermap[k],f))
9284 return qe_invalid;
9285 1152 }
9286
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9287 {
9288
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layerscreen[k],f))
9289 return qe_invalid;
9290 1152 }
9291
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9292 {
9293
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layeropacity[k],f))
9294 return qe_invalid;
9295 1152 }
9296
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 if(!p_putc(screen.hidelayers,f))
9297 return qe_invalid;
9298
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 if(!p_putc(screen.hidescriptlayers,f))
9299 return qe_invalid;
9300 192 }
9301
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
2082 if(scr_has_flags & SCRHAS_MAZE)
9302 {
9303
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
20 for(int32_t k=0; k<4; k++)
9304 {
9305
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_putc(screen.path[k],f))
9306 return qe_invalid;
9307 16 }
9308
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_putc(screen.exitdir,f))
9309 return qe_invalid;
9310 4 }
9311
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 2062 times.
2082 if(scr_has_flags & SCRHAS_D_S_U)
9312 {
9313
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_iputw(screen.door_combo_set,f))
9314 return qe_invalid;
9315
2/2
✓ Branch 0 taken 8248 times.
✓ Branch 1 taken 2062 times.
10310 for(int32_t k=0; k<4; k++)
9316 {
9317
1/2
✓ Branch 0 taken 8248 times.
✗ Branch 1 not taken.
8248 if(!p_putc(screen.door[k],f))
9318 return qe_invalid;
9319 8248 }
9320
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.stairx,f))
9321 return qe_invalid;
9322
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.stairy,f))
9323 return qe_invalid;
9324
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_iputw(screen.undercombo,f))
9325 return qe_invalid;
9326
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.undercset,f))
9327 return qe_invalid;
9328 2062 }
9329
2/2
✓ Branch 0 taken 1336 times.
✓ Branch 1 taken 746 times.
2082 if(scr_has_flags & SCRHAS_FLAGS)
9330 {
9331
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags,f))
9332 return qe_invalid;
9333
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags2,f))
9334 return qe_invalid;
9335
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags3,f))
9336 return qe_invalid;
9337
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags4,f))
9338 return qe_invalid;
9339
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags5,f))
9340 return qe_invalid;
9341
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags6,f))
9342 return qe_invalid;
9343
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags7,f))
9344 return qe_invalid;
9345
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags8,f))
9346 return qe_invalid;
9347
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags9,f))
9348 return qe_invalid;
9349
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags10,f))
9350 return qe_invalid;
9351
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.enemyflags,f))
9352 return qe_invalid;
9353 746 }
9354
2/2
✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 690 times.
2082 if(scr_has_flags & SCRHAS_ENEMY)
9355 {
9356
2/2
✓ Branch 0 taken 6900 times.
✓ Branch 1 taken 690 times.
7590 for(int32_t k=0; k<10; k++)
9357 {
9358
1/2
✓ Branch 0 taken 6900 times.
✗ Branch 1 not taken.
6900 if(!p_iputw(screen.enemy[k],f))
9359 return qe_invalid;
9360 6900 }
9361
1/2
✓ Branch 0 taken 690 times.
✗ Branch 1 not taken.
690 if(!p_putc(screen.pattern,f))
9362 return qe_invalid;
9363 690 }
9364
2/2
✓ Branch 0 taken 2076 times.
✓ Branch 1 taken 6 times.
2082 if(scr_has_flags & SCRHAS_CARRY)
9365 {
9366
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(screen.noreset,f))
9367 return qe_invalid;
9368
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(screen.nocarry,f))
9369 return qe_invalid;
9370
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_putc(screen.nextmap,f))
9371 return qe_invalid;
9372
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_putc(screen.nextscr,f))
9373 return qe_invalid;
9374 6 }
9375
2/2
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
2082 if(scr_has_flags & SCRHAS_SCRIPT)
9376 {
9377
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(screen.script,f))
9378 return qe_invalid;
9379
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(screen.preloadscript,f))
9380 return qe_invalid;
9381
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for ( int32_t q = 0; q < 8; q++ )
9382 {
9383
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_iputl(screen.screeninitd[q],f))
9384 return qe_invalid;
9385 144 }
9386 18 }
9387
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(scr_has_flags & SCRHAS_UNUSED)
9388 {
9389 for ( int32_t q = 0; q < 10; q++ )
9390 {
9391 if(!p_iputl(screen.npcstrings[q],f))
9392 return qe_invalid;
9393 }
9394 for ( int32_t q = 0; q < 10; q++ )
9395 {
9396 if(!p_iputw(screen.new_items[q],f))
9397 return qe_invalid;
9398 }
9399 for ( int32_t q = 0; q < 10; q++ )
9400 {
9401 if(!p_iputw(screen.new_item_x[q],f))
9402 return qe_invalid;
9403 }
9404 for ( int32_t q = 0; q < 10; q++ )
9405 {
9406 if(!p_iputw(screen.new_item_y[q],f))
9407 return qe_invalid;
9408 }
9409 }
9410
2/2
✓ Branch 0 taken 758 times.
✓ Branch 1 taken 1324 times.
2082 if(scr_has_flags & SCRHAS_SECRETS)
9411 {
9412
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9413 {
9414
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_iputw(screen.secretcombo[k],f))
9415 return qe_invalid;
9416 169472 }
9417
9418
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9419 {
9420
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_putc(screen.secretcset[k],f))
9421 return qe_invalid;
9422 169472 }
9423
9424
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9425 {
9426
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_putc(screen.secretflag[k],f))
9427 return qe_invalid;
9428 169472 }
9429 1324 }
9430
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 1910 times.
2082 if(scr_has_flags & SCRHAS_COMBOFLAG)
9431 {
9432
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9433 {
9434
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_iputw(screen.data[k],f))
9435 return qe_invalid;
9436 336160 }
9437
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9438 {
9439
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_putc(screen.sflag[k],f))
9440 return qe_invalid;
9441 336160 }
9442
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9443 {
9444
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_putc(screen.cset[k],f))
9445 return qe_invalid;
9446 336160 }
9447 1910 }
9448
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(scr_has_flags & SCRHAS_MISC)
9449 {
9450
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.color,f))
9451 return qe_invalid;
9452
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.csensitive,f))
9453 return qe_invalid;
9454
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.oceansfx,f))
9455 return qe_invalid;
9456
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.bosssfx,f))
9457 return qe_invalid;
9458
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.secretsfx,f))
9459 return qe_invalid;
9460
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.holdupsfx,f))
9461 return qe_invalid;
9462
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.timedwarptics,f))
9463 return qe_invalid;
9464
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.screen_midi,f))
9465 return qe_invalid;
9466
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.lens_layer,f))
9467 return qe_invalid;
9468
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.lens_show,f))
9469 return qe_invalid;
9470
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(!p_putc(screen.lens_hide,f))
9471 return qe_invalid;
9472 2082 }
9473
9474 2082 dword numffc = screen.numFFC();
9475
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(numffc,f))
9476 return qe_invalid;
9477
2/2
✓ Branch 0 taken 45816 times.
✓ Branch 1 taken 2082 times.
47898 for(int32_t k=0; k<numffc; ++k)
9478 {
9479 45816 ffcdata const& tempffc = screen.ffcs[k];
9480
9481
1/2
✓ Branch 0 taken 45816 times.
✗ Branch 1 not taken.
45816 if(!p_iputw(tempffc.data,f))
9482 return qe_invalid;
9483
9484
2/2
✓ Branch 0 taken 44726 times.
✓ Branch 1 taken 1090 times.
45816 if(!tempffc.data) //don't save the rest of the ffc
9485 44726 continue;
9486
9487
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.cset,f))
9488 return qe_invalid;
9489
9490
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputw(tempffc.delay,f))
9491 return qe_invalid;
9492
9493
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.x,f))
9494 return qe_invalid;
9495
9496
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.y,f))
9497 return qe_invalid;
9498
9499
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.vx,f))
9500 return qe_invalid;
9501
9502
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.vy,f))
9503 return qe_invalid;
9504
9505
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.ax,f))
9506 return qe_invalid;
9507
9508
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.ay,f))
9509 return qe_invalid;
9510
9511
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.link,f))
9512 return qe_invalid;
9513
9514
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.hit_width,f))
9515 return qe_invalid;
9516
9517
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.hit_height,f))
9518 return qe_invalid;
9519
9520
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.txsz,f))
9521 return qe_invalid;
9522
9523
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.tysz,f))
9524 return qe_invalid;
9525
9526
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.flags,f))
9527 return qe_invalid;
9528
9529
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputw(tempffc.script,f))
9530 return qe_invalid;
9531
9532
2/2
✓ Branch 0 taken 8720 times.
✓ Branch 1 taken 1090 times.
9810 for(auto q = 0; q < 8; ++q)
9533 {
9534
1/2
✓ Branch 0 taken 8720 times.
✗ Branch 1 not taken.
8720 if(!p_iputl(tempffc.initd[q],f))
9535 return qe_invalid;
9536 8720 }
9537
9538
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.inita[0]/10000,f))
9539 return qe_invalid;
9540
9541
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.inita[1]/10000,f))
9542 return qe_invalid;
9543 1090 }
9544
9545
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putlstr(screen.usr_notes, f))
9546 return qe_invalid;
9547
9548 2082 return qe_OK;
9549 4080 }
9550
9551 6 int32_t writemaps(PACKFILE *f, zquestheader *)
9552 {
9553 6 dword section_id=ID_MAPS;
9554 6 dword section_version=V_MAPS;
9555 6 dword section_cversion=CV_MAPS;
9556 6 dword section_size = 0;
9557
9558 //section id
9559
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
9560 {
9561 new_return(1);
9562 }
9563
9564 //section version info
9565
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
9566 {
9567 new_return(2);
9568 }
9569
9570
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
9571 {
9572 new_return(3);
9573 }
9574
9575
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9576 {
9577 12 fake_pack_writing=(writecycle==0);
9578
9579 //section size
9580
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
9581 {
9582 new_return(4);
9583 }
9584
9585 12 writesize=0;
9586
9587
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(map_count,f))
9588 {
9589 new_return(5);
9590 }
9591 12 map_autolayers.resize(map_count*6);
9592
4/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 12 times.
42 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9593 {
9594 30 byte valid = 0;
9595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 240 times.
240 for(int32_t j=0; j<MAPSCRS; j++)
9596 {
9597
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9598 break;
9599 240 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9600
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 210 times.
240 if(screen.valid & mVALID)
9601 {
9602 30 valid = 1;
9603 30 break;
9604 }
9605 210 }
9606
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!p_putc(valid,f))
9607 {
9608 new_return(6);
9609 }
9610
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!valid) continue;
9611
9612 { //per-map info
9613
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 30 times.
210 for(int q = 0; q < 6; ++q)
9614 {
9615 180 size_t ind = i*6+q;
9616
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
180 if(!p_iputw(map_autolayers[ind],f))
9617 new_return(7);
9618 180 }
9619 }
9620
9621
2/2
✓ Branch 0 taken 4080 times.
✓ Branch 1 taken 30 times.
4110 for(int32_t j=0; j<MAPSCRS; j++)
9622 4080 writemapscreen(f,i,j);
9623 30 }
9624
9625
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
9626 {
9627 6 section_size=writesize;
9628 6 }
9629 12 }
9630
9631
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
9632 {
9633 char ebuf[80];
9634 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9635 jwin_alert("Error: writemaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9636 }
9637
9638 6 new_return(0);
9639 }
9640
9641 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9642 {
9643 //Check what needs writing
9644 byte combo_has_flags = 0;
9645 383638 for(auto q = 0; q < 8; ++q)
9646 {
9647 767276 if(tmp_cmb.attribytes[q] || tmp_cmb.attrishorts[q]
9648 383638 || (q < 4 && tmp_cmb.attributes[q]))
9649 {
9650 combo_has_flags |= CHAS_ATTRIB;
9651 break;
9652 }
9653 383638 }
9654
3/4
✓ Branch 0 taken 96864 times.
✓ Branch 1 taken 96864 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96836 times.
96836 if (tmp_cmb.triggerflags[0] || tmp_cmb.triggerflags[1]
9655
3/4
✓ Branch 0 taken 96862 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 96862 times.
✗ Branch 3 not taken.
96864 || tmp_cmb.triggerflags[2] || tmp_cmb.triggerflags[3]
9656
3/4
✓ Branch 0 taken 96860 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96862 || tmp_cmb.triggerflags[4] || tmp_cmb.triggerflags[5]
9657
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.triggerlevel || tmp_cmb.trig_lstate
9658
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trig_gstate || tmp_cmb.trig_statetime
9659
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.triggerbtn || tmp_cmb.triggeritem
9660
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trigtimer || tmp_cmb.trigsfx
9661
3/4
✓ Branch 0 taken 96836 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trigchange || tmp_cmb.trigprox
9662
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigctr || tmp_cmb.trigctramnt
9663
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.triglbeam || tmp_cmb.trigcschange
9664
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.spawnitem || tmp_cmb.spawnenemy
9665
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.exstate > -1 || tmp_cmb.spawnip
9666
1/2
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
96836 || tmp_cmb.exdoor_dir > -1
9667
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigcopycat || tmp_cmb.trigcooldown
9668
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_genscr || tmp_cmb.trig_group
9669
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_group_val || tmp_cmb.trig_levelitems
9670
1/2
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
96836 || tmp_cmb.trigdmlevel > -1
9671
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.triglvlpalette > -1 || tmp_cmb.trigbosspalette > -1
9672
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigquaketime > -1 || tmp_cmb.trigwavytime > -1
9673
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_swjinxtime > -2 || tmp_cmb.trig_itmjinxtime > -2
9674
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_stuntime > -2 || tmp_cmb.trig_bunnytime > -2
9675
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_pushtime != 8 || tmp_cmb.trig_shieldjinxtime > -2
9676
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.prompt_cid || tmp_cmb.prompt_cs
9677
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.prompt_x != 12 || tmp_cmb.prompt_y != -8)
9678 96892 combo_has_flags |= CHAS_TRIG;
9679
2/2
✓ Branch 0 taken 290508 times.
✓ Branch 1 taken 96836 times.
387344 else for(int q = 0; q < 3; ++q)
9680
1/2
✓ Branch 0 taken 290508 times.
✗ Branch 1 not taken.
290508 if(tmp_cmb.trigtint[q])
9681 combo_has_flags |= CHAS_TRIG;
9682
4/4
✓ Branch 0 taken 96840 times.
✓ Branch 1 taken 96888 times.
✓ Branch 2 taken 96704 times.
✓ Branch 3 taken 136 times.
193728 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9683 193592 combo_has_flags |= CHAS_FLAG;
9684
6/6
✓ Branch 0 taken 93610 times.
✓ Branch 1 taken 93290 times.
✓ Branch 2 taken 80124 times.
✓ Branch 3 taken 13486 times.
✓ Branch 4 taken 89494 times.
✓ Branch 5 taken 9434 times.
80380 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9685
6/6
✓ Branch 0 taken 80100 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 80070 times.
✓ Branch 3 taken 30 times.
✓ Branch 4 taken 80060 times.
✓ Branch 5 taken 10 times.
80124 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9686
1/2
✓ Branch 0 taken 80060 times.
✗ Branch 1 not taken.
80060 || tmp_cmb.animflags)
9687 196334 combo_has_flags |= CHAS_ANIM;
9688
3/4
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 70224 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 97004 times.
26780 if(tmp_cmb.script || tmp_cmb.label.size())
9689 70224 combo_has_flags |= CHAS_SCRIPT;
9690
2/2
✓ Branch 0 taken 776032 times.
✓ Branch 1 taken 97004 times.
873036 else for(auto q = 0; q < 8; ++q)
9691 {
9692
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 776032 times.
776032 if(tmp_cmb.initd[q])
9693 {
9694 combo_has_flags |= CHAS_SCRIPT;
9695 break;
9696 }
9697 776032 }
9698
6/6
✓ Branch 0 taken 52696 times.
✓ Branch 1 taken 114532 times.
✓ Branch 2 taken 52184 times.
✓ Branch 3 taken 512 times.
✓ Branch 4 taken 70224 times.
✓ Branch 5 taken 18040 times.
219412 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9699
2/4
✓ Branch 0 taken 52184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 52184 times.
✗ Branch 3 not taken.
52184 || tmp_cmb.type || tmp_cmb.csets)
9700 185268 combo_has_flags |= CHAS_BASIC;
9701
3/4
✓ Branch 0 taken 96996 times.
✓ Branch 1 taken 34136 times.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
159856 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9702
3/6
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
96996 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9703
3/6
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
96996 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9704
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9705
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9706
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9707
1/2
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
96996 || tmp_cmb.lift_parent_item)
9708 131132 combo_has_flags |= CHAS_LIFT;
9709
3/4
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 34128 times.
✓ Branch 2 taken 97004 times.
✗ Branch 3 not taken.
228128 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9710
7/10
✓ Branch 0 taken 97004 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 97000 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 96996 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 96996 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 96996 times.
✗ Branch 9 not taken.
97004 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9711
5/10
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 96996 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 96996 times.
✗ Branch 9 not taken.
96996 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap)
9712 131132 combo_has_flags |= CHAS_GENERAL;
9713
9714
2/2
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 34128 times.
131132 if(!p_putc(combo_has_flags,f))
9715 {
9716 34128 return 50;
9717 }
9718
2/2
✓ Branch 0 taken 44820 times.
✓ Branch 1 taken 52184 times.
97004 if(!combo_has_flags) return 0; //Valid, done reading
9719 //Write the combo
9720
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44820 times.
44820 if(combo_has_flags&CHAS_BASIC)
9721 {
9722
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_iputl(tmp_cmb.o_tile,f))
9723 return 6;
9724
9725
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.flip,f))
9726 return 7;
9727
9728
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.walk,f))
9729 return 8;
9730
9731
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.type,f))
9732 return 9;
9733
9734
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.flag,f))
9735 return 15;
9736
9737
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.csets,f))
9738 return 10;
9739 44820 }
9740
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(combo_has_flags&CHAS_SCRIPT)
9741 {
9742 p_putcstr(tmp_cmb.label, f);
9743
9744 if(!p_iputw(tmp_cmb.script,f))
9745 return 26;
9746 for ( int32_t q = 0; q < 8; q++ )
9747 if(!p_iputl(tmp_cmb.initd[q],f))
9748 return 27;
9749 }
9750
2/2
✓ Branch 0 taken 27474 times.
✓ Branch 1 taken 17346 times.
44820 if(combo_has_flags&CHAS_ANIM)
9751 {
9752
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.frames,f))
9753 return 11;
9754
9755
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.speed,f))
9756 return 12;
9757
9758
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_iputw(tmp_cmb.nextcombo,f))
9759 return 13;
9760
9761
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.nextcset,f))
9762 return 14;
9763
9764
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.skipanim,f))
9765 return 16;
9766
9767
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.skipanimy,f))
9768 return 18;
9769
9770
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.animflags,f))
9771 return 19;
9772 17346 }
9773
2/2
✓ Branch 0 taken 42552 times.
✓ Branch 1 taken 2268 times.
44820 if(combo_has_flags&CHAS_ATTRIB)
9774 {
9775
2/2
✓ Branch 0 taken 9072 times.
✓ Branch 1 taken 2268 times.
11340 for ( int32_t q = 0; q < 4; q++ )
9776
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9072 times.
9072 if(!p_iputl(tmp_cmb.attributes[q],f))
9777 return 20;
9778
2/2
✓ Branch 0 taken 18144 times.
✓ Branch 1 taken 2268 times.
20412 for ( int32_t q = 0; q < 8; q++ )
9779
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18144 times.
18144 if(!p_putc(tmp_cmb.attribytes[q],f))
9780 return 25;
9781
2/2
✓ Branch 0 taken 18144 times.
✓ Branch 1 taken 2268 times.
20412 for ( int32_t q = 0; q < 8; q++ ) //I also added attrishorts -Dimi
9782
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18144 times.
18144 if(!p_iputw(tmp_cmb.attrishorts[q],f))
9783 return 32;
9784 2268 }
9785
2/2
✓ Branch 0 taken 44636 times.
✓ Branch 1 taken 184 times.
44820 if(combo_has_flags&CHAS_FLAG)
9786 {
9787
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 184 times.
184 if(!p_iputl(tmp_cmb.usrflags,f))
9788 return 21;
9789
1/2
✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
184 if(!p_iputw(tmp_cmb.genflags,f))
9790 return 33;
9791 184 }
9792
2/2
✓ Branch 0 taken 44652 times.
✓ Branch 1 taken 168 times.
44820 if(combo_has_flags&CHAS_TRIG)
9793 {
9794
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 168 times.
1176 for ( int32_t q = 0; q < 6; q++ )
9795
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1008 times.
1008 if(!p_iputl(tmp_cmb.triggerflags[q],f))
9796 return 22;
9797
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.triggerlevel,f))
9798 return 23;
9799
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triggerbtn,f))
9800 return 34;
9801
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triggeritem,f))
9802 return 35;
9803
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigtimer,f))
9804 return 36;
9805
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigsfx,f))
9806 return 37;
9807
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trigchange,f))
9808 return 38;
9809
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
168 if(!p_iputw(tmp_cmb.trigprox,f))
9810 return 39;
9811
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigctr,f))
9812 return 40;
9813
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trigctramnt,f))
9814 return 41;
9815
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triglbeam,f))
9816 return 42;
9817
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcschange,f))
9818 return 43;
9819
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.spawnitem,f))
9820 return 44;
9821
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.spawnenemy,f))
9822 return 45;
9823
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exstate,f))
9824 return 46;
9825
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.spawnip,f))
9826 return 47;
9827
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcopycat,f))
9828 return 48;
9829
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcooldown,f))
9830 return 49;
9831
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_cid,f))
9832 return 50;
9833
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.prompt_cs,f))
9834 return 51;
9835
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_x,f))
9836 return 52;
9837
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_y,f))
9838 return 53;
9839
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_lstate,f))
9840 return 69;
9841
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_gstate,f))
9842 return 70;
9843
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trig_statetime,f))
9844 return 71;
9845
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_genscr,f))
9846 return 72;
9847
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_group,f))
9848 return 76;
9849
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_group_val,f))
9850 return 77;
9851
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exdoor_dir,f))
9852 return 89;
9853
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exdoor_ind,f))
9854 return 90;
9855
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_levelitems,f))
9856 return 91;
9857
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigdmlevel,f))
9858 return 92;
9859
2/2
✓ Branch 0 taken 504 times.
✓ Branch 1 taken 168 times.
672 for(int q = 0; q < 3; ++q)
9860
1/2
✓ Branch 0 taken 504 times.
✗ Branch 1 not taken.
504 if(!p_iputw(tmp_cmb.trigtint[q],f))
9861 return 93;
9862
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.triglvlpalette,f))
9863 return 94;
9864
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigbosspalette,f))
9865 return 95;
9866
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigquaketime,f))
9867 return 96;
9868
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigwavytime,f))
9869 return 97;
9870
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_swjinxtime,f))
9871 return 98;
9872
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_itmjinxtime,f))
9873 return 99;
9874
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_stuntime,f))
9875 return 100;
9876
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_bunnytime,f))
9877 return 101;
9878
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_pushtime,f))
9879 return 102;
9880
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if (!p_iputw(tmp_cmb.trig_shieldjinxtime, f))
9881 return 103;
9882 168 }
9883
2/2
✓ Branch 0 taken 44812 times.
✓ Branch 1 taken 8 times.
44820 if(combo_has_flags&CHAS_LIFT)
9884 {
9885
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftcmb,f))
9886 return 54;
9887
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftcs,f))
9888 return 55;
9889
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftundercmb,f))
9890 return 56;
9891
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftundercs,f))
9892 return 57;
9893
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftdmg,f))
9894 return 58;
9895
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftlvl,f))
9896 return 59;
9897
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftitm,f))
9898 return 60;
9899
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftflags,f))
9900 return 61;
9901
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftgfx,f))
9902 return 62;
9903
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftsprite,f))
9904 return 63;
9905
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftsfx,f))
9906 return 64;
9907
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9908 return 65;
9909
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9910 return 66;
9911
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lifthei,f))
9912 return 67;
9913
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lifttime,f))
9914 return 68;
9915
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lift_parent_item,f))
9916 return 78;
9917 8 }
9918
2/2
✓ Branch 0 taken 44812 times.
✓ Branch 1 taken 8 times.
44820 if(combo_has_flags&CHAS_GENERAL)
9919 {
9920
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.speed_mult,f))
9921 return 73;
9922
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.speed_div,f))
9923 return 74;
9924
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputzf(tmp_cmb.speed_add,f))
9925 return 75;
9926
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_appear,f))
9927 return 79;
9928
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(!p_putc(tmp_cmb.sfx_disappear,f))
9929 return 80;
9930
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_loop,f))
9931 return 81;
9932
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_walking,f))
9933 return 82;
9934
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_standing,f))
9935 return 83;
9936
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_appear,f))
9937 return 84;
9938
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_disappear,f))
9939 return 85;
9940
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_walking,f))
9941 return 86;
9942
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_standing,f))
9943 return 87;
9944
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_tap,f))
9945 return 88;
9946 8 }
9947 44820 return 0;
9948 131132 }
9949
9950 6 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9951 {
9952 //these are here to bypass compiler warnings about unused arguments
9953 6 version=version;
9954 6 build=build;
9955
9956 word combos_used;
9957 6 dword section_id=ID_COMBOS;
9958 6 dword section_version=V_COMBOS;
9959 6 dword section_cversion=CV_COMBOS;
9960 // dword section_size=0;
9961 6 combos_used = count_combos()-start_combo;
9962
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 combos_used = zc_min(combos_used, max_combos);
9963
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 combos_used = zc_min(combos_used, MAXCOMBOS);
9964 6 dword section_size = 0;
9965
9966 //section id
9967
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
9968 {
9969 new_return(1);
9970 }
9971
9972 //section version info
9973
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
9974 {
9975 new_return(2);
9976 }
9977
9978
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
9979 {
9980 new_return(3);
9981 }
9982
9983
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9984 {
9985 12 fake_pack_writing=(writecycle==0);
9986
9987 //section size
9988
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
9989 {
9990 new_return(4);
9991 }
9992
9993 12 writesize=0;
9994
9995 //finally... section data
9996 12 combos_used=count_combos()-start_combo;
9997
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 combos_used=zc_min(combos_used, max_combos);
9998
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 combos_used=zc_min(combos_used, MAXCOMBOS);
9999
10000
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(combos_used,f))
10001 {
10002 new_return(5);
10003 }
10004
10005 12 size_t end_combo = start_combo+combos_used;
10006
2/2
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 12 times.
97016 for(size_t q = start_combo; q < end_combo; ++q)
10007 {
10008 97004 auto ret = writecombo_loop(f, section_version, combobuf[q]);
10009
1/4
✓ Branch 0 taken 97004 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
97004 if(ret) new_return(ret);
10010 97004 }
10011
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10012 {
10013 6 section_size=writesize;
10014 6 }
10015 12 }
10016
10017
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10018 {
10019 char ebuf[80];
10020 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10021 jwin_alert("Error: writecombos()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10022 }
10023
10024 6 new_return(0);
10025 6 }
10026
10027 6 int32_t writecomboaliases(PACKFILE *f, word version, word build)
10028 {
10029 //these are here to bypass compiler warnings about unused arguments
10030 6 version=version;
10031 6 build=build;
10032
10033 6 dword section_id=ID_COMBOALIASES;
10034 6 dword section_version=V_COMBOALIASES;
10035 6 dword section_cversion=CV_COMBOALIASES;
10036 6 dword section_size=0;
10037
10038 //section id
10039
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10040 {
10041 new_return(1);
10042 }
10043
10044 //section version info
10045
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10046 {
10047 new_return(2);
10048 }
10049
10050
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10051 {
10052 new_return(3);
10053 }
10054
10055
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10056 {
10057 12 fake_pack_writing=(writecycle==0);
10058
10059 //section size
10060
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10061 {
10062 new_return(4);
10063 }
10064
10065 12 writesize=0;
10066
10067 //finally... section data
10068
2/2
✓ Branch 0 taken 98304 times.
✓ Branch 1 taken 12 times.
98316 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
10069 {
10070
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_iputw(combo_aliases[j].combo,f))
10071 {
10072 new_return(5);
10073 }
10074
10075
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].cset,f))
10076 {
10077 new_return(6);
10078 }
10079
10080 98304 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
10081
10082
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].width,f))
10083 {
10084 new_return(7);
10085 }
10086
10087
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].height,f))
10088 {
10089 new_return(8);
10090 }
10091
10092
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].layermask,f))
10093 {
10094 new_return(9);
10095 }
10096
10097
2/2
✓ Branch 0 taken 99792 times.
✓ Branch 1 taken 98304 times.
198096 for(int32_t k=0; k<count; k++)
10098 {
10099
1/2
✓ Branch 0 taken 99792 times.
✗ Branch 1 not taken.
99792 if(!p_iputw(combo_aliases[j].combos[k],f))
10100 {
10101 new_return(10);
10102 }
10103 99792 }
10104
10105
2/2
✓ Branch 0 taken 99792 times.
✓ Branch 1 taken 98304 times.
198096 for(int32_t k=0; k<count; k++)
10106 {
10107
1/2
✓ Branch 0 taken 99792 times.
✗ Branch 1 not taken.
99792 if(!p_putc(combo_aliases[j].csets[k],f))
10108 {
10109 new_return(11);
10110 }
10111 99792 }
10112 98304 }
10113
10114 //Combo pools!
10115 int16_t num_cpools;
10116
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 98300 times.
98310 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10117 {
10118
2/2
✓ Branch 0 taken 98298 times.
✓ Branch 1 taken 2 times.
98300 if(combo_pools[num_cpools].valid()) //found a used pool
10119 {
10120 2 ++num_cpools;
10121 2 break;
10122 }
10123 98298 }
10124
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10 times.
12 if(num_cpools < 0) num_cpools = 0;
10125
10126
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(num_cpools,f))
10127 {
10128 new_return(12);
10129 }
10130
10131
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(auto cp = 0; cp < num_cpools; ++cp)
10132 {
10133 6 combo_pool const& pool = combo_pools[cp];
10134 6 int32_t num_combos = pool.combos.size();
10135
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10136 {
10137 new_return(13);
10138 }
10139
10140
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10141 {
10142 26 cpool_entry const& entry = pool.combos.at(q);
10143
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10144 {
10145 new_return(14);
10146 }
10147
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10148 {
10149 new_return(15);
10150 }
10151
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(entry.quant,f))
10152 {
10153 new_return(16);
10154 }
10155 26 }
10156 6 }
10157
10158 //Autocombos!
10159 int16_t num_cautos;
10160
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 98304 times.
98316 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10161 {
10162
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if (combo_autos[num_cautos].valid()) //found a used autocombo
10163 {
10164 ++num_cautos;
10165 break;
10166 }
10167 98304 }
10168
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (num_cautos < 0) num_cautos = 0;
10169
10170
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_iputw(num_cautos, f))
10171 {
10172 new_return(17);
10173 }
10174
10175
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 for (auto ca = 0; ca < num_cautos; ++ca)
10176 {
10177 combo_auto const& cauto = combo_autos[ca];
10178 if (!p_putc(cauto.getType(), f))
10179 {
10180 new_return(18);
10181 }
10182 if (!p_iputl(cauto.getIconDisplay(), f))
10183 {
10184 new_return(19);
10185 }
10186 if (!p_iputl(cauto.getEraseCombo(), f))
10187 {
10188 new_return(20);
10189 }
10190 if (!p_putc(cauto.getFlags(), f))
10191 {
10192 new_return(21);
10193 }
10194 if (!p_putc(cauto.getArg(), f))
10195 {
10196 new_return(22);
10197 }
10198 int32_t num_combos = cauto.combos.size();
10199 if (!p_iputl(num_combos, f))
10200 {
10201 new_return(23);
10202 }
10203
10204 for (auto q = 0; q < num_combos; ++q)
10205 {
10206 autocombo_entry const& entry = cauto.combos.at(q);
10207 if (!p_putc(entry.ctype, f))
10208 {
10209 new_return(24);
10210 }
10211 if (!p_iputl(entry.cid, f))
10212 {
10213 new_return(25);
10214 }
10215 }
10216 }
10217
10218
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10219 {
10220 6 section_size=writesize;
10221 6 }
10222 12 }
10223
10224
10225
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10226 {
10227 char ebuf[80];
10228 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10229 jwin_alert("Error: writecomboaliases()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10230 }
10231
10232 6 new_return(0);
10233 }
10234
10235 6 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10236 {
10237 //these are here to bypass compiler warnings about unused arguments
10238 6 version=version;
10239 6 build=build;
10240 6 start_cset=start_cset;
10241 6 max_csets=max_csets;
10242
10243 6 dword section_id=ID_CSETS;
10244 6 dword section_version=V_CSETS;
10245 6 dword section_cversion=CV_CSETS;
10246 6 int32_t palcycles = count_palcycles(&QMisc);
10247 // int32_t palcyccount = count_palcycles(&QMisc);
10248 6 dword section_size = 0;
10249
10250 //section id
10251
10252
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10253 {
10254 new_return(1);
10255 }
10256
10257 //section version info
10258
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10259 {
10260 new_return(2);
10261 }
10262
10263
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10264 {
10265 new_return(3);
10266 }
10267
10268
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10269 {
10270 12 fake_pack_writing=(writecycle==0);
10271
10272 //section size
10273
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10274 {
10275 new_return(4);
10276 }
10277
10278 12 writesize=0;
10279
10280 //finally... section data
10281
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(colordata,psTOTAL255,f))
10282 {
10283 new_return(5);
10284 }
10285
10286
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10287 {
10288 new_return(6);
10289 }
10290
10291
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(palcycles,f))
10292 {
10293 new_return(15);
10294 }
10295
10296
2/2
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 12 times.
288 for(int32_t i=0; i<palcycles; i++)
10297 {
10298
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10299 {
10300
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].first,f))
10301 {
10302 new_return(16);
10303 }
10304 828 }
10305
10306
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10307 {
10308
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].count,f))
10309 {
10310 new_return(17);
10311 }
10312 828 }
10313
10314
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10315 {
10316
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].speed,f))
10317 {
10318 new_return(18);
10319 }
10320 828 }
10321 276 }
10322
10323
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10324 {
10325 6 section_size=writesize;
10326 6 }
10327 12 }
10328
10329
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10330 {
10331 char ebuf[80];
10332 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10333 jwin_alert("Error: writecolordata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10334 }
10335
10336 6 new_return(0);
10337 }
10338
10339 6 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10340 {
10341 //these are here to bypass compiler warnings about unused arguments
10342 6 version=version;
10343 6 build=build;
10344 6 start_msgstr=start_msgstr;
10345 6 max_msgstrs=max_msgstrs;
10346
10347 6 dword section_id=ID_STRINGS;
10348 6 dword section_version=V_STRINGS;
10349 6 dword section_cversion=CV_STRINGS;
10350 6 dword section_size = 0;
10351
10352 //section id
10353
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10354 {
10355 new_return(1);
10356 }
10357
10358 //section version info
10359
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10360 {
10361 new_return(2);
10362 }
10363
10364
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10365 {
10366 new_return(3);
10367 }
10368
10369
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10370 {
10371 12 fake_pack_writing=(writecycle==0);
10372
10373 //section size
10374
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10375 {
10376 new_return(4);
10377 }
10378
10379 12 writesize=0;
10380
10381 //finally... section data
10382
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(msg_count,f))
10383 {
10384 return qe_invalid;
10385 }
10386
10387
2/2
✓ Branch 0 taken 302 times.
✓ Branch 1 taken 12 times.
314 for(int32_t i=0; i<msg_count; i++)
10388 {
10389 302 int32_t sz = MsgStrings[i].s.size();
10390
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(sz > 8192) sz = 8192;
10391
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(sz, f))
10392 {
10393 return qe_invalid;
10394 }
10395
10396 302 char const* tmpstr = MsgStrings[i].s.c_str();
10397
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 302 times.
302 if (sz > 0)
10398 {
10399
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if (!pfwrite((void*)tmpstr,sz, f))
10400 {
10401 return qe_invalid;
10402 }
10403 302 }
10404
10405
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].nextstring,f))
10406 {
10407 return qe_invalid;
10408 }
10409
10410
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(MsgStrings[i].tile,f))
10411 {
10412 return qe_invalid;
10413 }
10414
10415
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].cset,f))
10416 {
10417 return qe_invalid;
10418 }
10419
10420
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].trans?1:0,f))
10421 {
10422 return qe_invalid;
10423 }
10424
10425
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].font,f))
10426 {
10427 return qe_invalid;
10428 }
10429
10430
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].x,f))
10431 {
10432 return qe_invalid;
10433 }
10434
10435
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].y,f))
10436 {
10437 return qe_invalid;
10438 }
10439
10440
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].w,f))
10441 {
10442 return qe_invalid;
10443 }
10444
10445
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].h,f))
10446 {
10447 return qe_invalid;
10448 }
10449
10450
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].hspace,f))
10451 {
10452 return qe_invalid;
10453 }
10454
10455
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].vspace,f))
10456 {
10457 return qe_invalid;
10458 }
10459
10460
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].stringflags,f))
10461 {
10462 return qe_invalid;
10463 }
10464
10465
2/2
✓ Branch 0 taken 1208 times.
✓ Branch 1 taken 302 times.
1510 for(int32_t q = 0; q < 4; ++q)
10466 {
10467
1/2
✓ Branch 0 taken 1208 times.
✗ Branch 1 not taken.
1208 if(!p_putc(MsgStrings[i].margins[q],f))
10468 {
10469 return qe_invalid;
10470 }
10471 1208 }
10472
10473
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10474 {
10475 return qe_invalid;
10476 }
10477
10478
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_cset,f))
10479 {
10480 return qe_invalid;
10481 }
10482
10483
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_x,f))
10484 {
10485 return qe_invalid;
10486 }
10487
10488
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_y,f))
10489 {
10490 return qe_invalid;
10491 }
10492
10493
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_tw,f))
10494 {
10495 return qe_invalid;
10496 }
10497
10498
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_th,f))
10499 {
10500 return qe_invalid;
10501 }
10502
10503
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].shadow_type,f))
10504 {
10505 return qe_invalid;
10506 }
10507
10508
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].shadow_color,f))
10509 {
10510 return qe_invalid;
10511 }
10512
10513
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].drawlayer,f))
10514 {
10515 return qe_invalid;
10516 }
10517
10518
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].sfx,f))
10519 {
10520 return qe_invalid;
10521 }
10522
10523
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].listpos,f))
10524 {
10525 return qe_invalid;
10526 }
10527 302 }
10528
10529
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10530 {
10531 6 section_size=writesize;
10532 6 }
10533 12 }
10534
10535
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10536 {
10537 char ebuf[80];
10538 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10539 jwin_alert("Error: writestrings()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10540 }
10541
10542 6 new_return(0);
10543 6 }
10544
10545 int32_t writestrings_text(PACKFILE *f)
10546 {
10547 std::map<int32_t, int32_t> msglistcache;
10548
10549 for(int32_t index = 1; index<msg_count; index++)
10550 {
10551 for(int32_t i=1; i<msg_count; i++)
10552 {
10553 if(MsgStrings[i].listpos==index)
10554 {
10555 msglistcache[index-1]=i;
10556 break;
10557 }
10558 }
10559 }
10560
10561 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10562 {
10563 fake_pack_writing=(writecycle==0);
10564 char ebuf[32];
10565
10566 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10567
10568 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10569 {
10570 return qe_invalid;
10571 }
10572
10573 for(int32_t i=1; i<msg_count; i++)
10574 {
10575 int32_t str = msglistcache[i-1];
10576
10577 if(!str)
10578 continue;
10579
10580 if(MsgStrings[str].nextstring != 0)
10581 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10582 else
10583 sprintf(ebuf,"\n\n___%d___\n", str);
10584
10585 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10586 {
10587 return qe_invalid;
10588 }
10589
10590 encode_msg_str(str);
10591
10592 if(!pfwrite(&msgbuf,(int32_t)strlen(msgbuf),f))
10593 {
10594 return qe_invalid;
10595 }
10596 }
10597 }
10598
10599 new_return(0);
10600 }
10601
10602 1 int32_t writestrings_tsv(PACKFILE *f)
10603 {
10604 1 std::stringstream ss;
10605
10606 int32_t str;
10607
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10608
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){
10609 35 encode_msg_str(str);
10610 35 return msgbuf;
10611 }},
10612
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10613
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10614
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10615
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10616
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10617
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10618
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10619
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10620
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10621
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10622
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10623
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10624
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10625
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10626
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10627
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10628
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10629
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10630
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10631
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10632
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10633
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10634
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10635
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10636 };
10637
10638
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10639 {
10640
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10641
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10642 1 break;
10643
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10644 }
10645
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10646
10647 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10648
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10649
10650
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10651 {
10652 35 str = i;
10653 35 auto& msg = MsgStrings[str];
10654
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10655 {
10656
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10657
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10658
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10659 35 break;
10660
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10661
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10662
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10663 35 }
10664
10665
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10666
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10667 {
10668 return qe_invalid;
10669 }
10670
10671 1 new_return(0);
10672 1 }
10673
10674 std::string parse_msg_str(std::string const& s);
10675
10676 void parse_strings_tsv(std::string tsv)
10677 {
10678 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10679 { "message", [](auto& msg, auto& text){ msg.s = parse_msg_str(text); } },
10680 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10681 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10682 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10683 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10684 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10685 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10686 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10687 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10688 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10689 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10690 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10691 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10692 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10693 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10694 { "margin", [&](auto& msg, auto& text){
10695 std::vector<std::string> strs;
10696 util::split(text, strs, ' ');
10697 if (strs.size() != 4)
10698 throw std::runtime_error("margin field must have 4 components");
10699 msg.margins[0] = std::stoi(strs[0]);
10700 msg.margins[1] = std::stoi(strs[1]);
10701 msg.margins[2] = std::stoi(strs[2]);
10702 msg.margins[3] = std::stoi(strs[3]);
10703 } },
10704 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10705 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10706 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10707 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10708 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10709 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10710 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10711 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10712 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10713 };
10714
10715 std::vector<std::string> rows;
10716 util::split(tsv, rows, '\n');
10717 if (rows.size())
10718 {
10719 std::string last = rows.back();
10720 util::trimstr(last);
10721 if (last.empty())
10722 rows.pop_back();
10723 }
10724 if (rows.size() <= 1)
10725 throw std::runtime_error("missing header row");
10726
10727 std::vector<std::string> columns;
10728 util::split(rows[0], columns, '\t');
10729 for (auto name : columns)
10730 {
10731 if (!fields.contains(name))
10732 throw std::runtime_error(fmt::format("invalid field: {}", name));
10733 }
10734
10735 int start_index = 1;
10736 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10737 start_index += 1;
10738
10739 int num_strings = rows.size() - start_index + 1;
10740 if (num_strings > MAXMSGS-1)
10741 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10742
10743 std::vector<MsgStr> msgs;
10744 msgs.reserve(num_strings);
10745 for (int i = start_index; i < rows.size(); i++)
10746 {
10747 std::vector<std::string> strs;
10748 util::split(rows[i], strs, '\t');
10749 if (strs.size() != columns.size())
10750 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10751
10752 int j = 0;
10753 auto& msg = msgs.emplace_back();
10754 for (auto& name : columns)
10755 {
10756 auto& fn = fields[name];
10757 try
10758 {
10759 fn(msg, strs[j++]);
10760 }
10761 catch (std::exception& ex)
10762 {
10763 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10764 }
10765 }
10766 }
10767
10768 init_msgstrings(0, msgs.size());
10769 for (int i = 0; i < msgs.size(); i++)
10770 MsgStrings[i + 1] = msgs[i];
10771 msg_count = msgs.size();
10772 msglistcache.clear();
10773 }
10774
10775 bool isblanktile(tiledata *buf, int32_t i);
10776 6 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10777 {
10778 //these are here to bypass compiler warnings about unused arguments
10779 6 version=version;
10780 6 build=build;
10781
10782 int32_t tiles_used;
10783 6 dword section_id=ID_TILES;
10784 6 dword section_version=V_TILES;
10785 6 dword section_cversion=CV_TILES;
10786 6 al_trace("Counting tiles used\n");
10787 6 tiles_used = count_tiles(newtilebuf)-start_tile;
10788
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 tiles_used = zc_min(tiles_used, max_tiles);
10789
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10790 6 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10791 6 dword section_size = 0;
10792
10793 //section id
10794
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10795 {
10796 new_return(1);
10797 }
10798
10799 //section version info
10800
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10801 {
10802 new_return(2);
10803 }
10804
10805
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10806 {
10807 new_return(3);
10808 }
10809
10810
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10811 {
10812 12 fake_pack_writing=(writecycle==0);
10813
10814 //section size
10815
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10816 {
10817 new_return(4);
10818 }
10819
10820 12 writesize=0;
10821
10822 //finally... section data
10823 12 tiles_used=count_tiles(newtilebuf)-start_tile;
10824
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 tiles_used=zc_min(tiles_used, max_tiles);
10825
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10826
10827
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(tiles_used,f))
10828 {
10829 new_return(5);
10830 }
10831
10832
2/2
✓ Branch 0 taken 448054 times.
✓ Branch 1 taken 12 times.
448066 for(int32_t i=0; i<tiles_used; ++i)
10833 {
10834
2/2
✓ Branch 0 taken 238750 times.
✓ Branch 1 taken 209304 times.
448054 if(isblanktile(newtilebuf, start_tile+i))
10835 {
10836
1/2
✓ Branch 0 taken 238750 times.
✗ Branch 1 not taken.
238750 if(!p_putc(0,f))
10837 new_return(8);
10838 238750 }
10839 else
10840 {
10841 209304 int format = newtilebuf[start_tile+i].format;
10842
1/2
✓ Branch 0 taken 209304 times.
✗ Branch 1 not taken.
209304 if(!p_putc(format,f))
10843 {
10844 new_return(6);
10845 }
10846
10847
2/2
✓ Branch 0 taken 207706 times.
✓ Branch 1 taken 1598 times.
209304 if (format == tf4Bit)
10848 {
10849 byte temp_tile[128];
10850 207706 byte *di = temp_tile;
10851 207706 byte *src = newtilebuf[start_tile+i].data;
10852
2/2
✓ Branch 0 taken 26586368 times.
✓ Branch 1 taken 207706 times.
26794074 for (int32_t si=0; si<256; si+=2)
10853 {
10854 26586368 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10855 26586368 ++di;
10856 26586368 }
10857
1/2
✓ Branch 0 taken 207706 times.
✗ Branch 1 not taken.
207706 if (!pfwrite(temp_tile,128,f))
10858 {
10859 new_return(7);
10860 }
10861 207706 }
10862
1/2
✓ Branch 0 taken 1598 times.
✗ Branch 1 not taken.
1598 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10863 {
10864 new_return(7);
10865 }
10866 }
10867 448054 }
10868
10869
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10870 {
10871 6 section_size=writesize;
10872 6 }
10873 12 }
10874
10875
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10876 {
10877 char ebuf[80];
10878 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10879 jwin_alert("Error: writetiles()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10880 }
10881
10882 6 new_return(0);
10883 }
10884
10885 /* MIDI Format
10886 section_id LONG
10887 section_version WORD
10888 section_cversion WORD
10889 section_size LONG
10890 midi_flags 32 Byte ? BITFIELD[252]
10891
10892 [
10893 title 36
10894 start 4
10895 loop_start 4
10896 loop_end 4
10897 loop 2
10898 volume 2
10899 midi *
10900 ]
10901
10902 */
10903
10904 6 int32_t writemidis(PACKFILE *f)
10905 {
10906 6 dword section_id=ID_MIDIS;
10907 6 dword section_version=V_MIDIS;
10908 6 dword section_cversion=CV_MIDIS;
10909 6 dword section_size = 0;
10910
10911 //section id
10912
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10913 {
10914 new_return(1);
10915 }
10916
10917 //section version info
10918
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10919 {
10920 new_return(2);
10921 }
10922
10923
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10924 {
10925 new_return(3);
10926 }
10927
10928
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10929 {
10930 12 fake_pack_writing=(writecycle==0);
10931
10932 //section size
10933
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10934 {
10935 new_return(4);
10936 }
10937
10938 12 writesize=0;
10939
10940 //finally... section data
10941
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10942 {
10943 new_return(5);
10944 }
10945
10946
2/2
✓ Branch 0 taken 3024 times.
✓ Branch 1 taken 12 times.
3036 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10947 {
10948
2/2
✓ Branch 0 taken 2964 times.
✓ Branch 1 taken 60 times.
3024 if(get_bit(midi_flags,i))
10949 {
10950
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10951 {
10952 new_return(6);
10953 }
10954
10955
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].start,f))
10956 {
10957 new_return(7);
10958 }
10959
10960
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].loop_start,f))
10961 {
10962 new_return(8);
10963 }
10964
10965
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].loop_end,f))
10966 {
10967 new_return(9);
10968 }
10969
10970
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputw(customtunes[i].loop,f))
10971 {
10972 new_return(10);
10973 }
10974
10975
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputw(customtunes[i].volume,f))
10976 {
10977 new_return(11);
10978 }
10979
10980
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
10981 {
10982 new_return(12);
10983 }
10984
10985 60 byte format = MFORMAT_MIDI;
10986
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&format, sizeof(format),f))
10987 {
10988 new_return(13);
10989 }
10990
10991
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if (!write_midi(customtunes[i].data, f)) new_return(14);
10992 60 }
10993 3024 }
10994
10995
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10996 {
10997 6 section_size=writesize;
10998 6 }
10999 12 }
11000
11001
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11002 {
11003 char ebuf[80];
11004 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11005 jwin_alert("Error: writemidis()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11006 }
11007
11008 6 new_return(0);
11009 }
11010
11011 6 int32_t writecheats(PACKFILE *f, zquestheader *Header)
11012 {
11013 6 dword section_id=ID_CHEATS;
11014 6 dword section_version=V_CHEATS;
11015 6 dword section_cversion=CV_CHEATS;
11016 6 dword section_size = 0;
11017
11018 //section id
11019
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11020 {
11021 new_return(1);
11022 }
11023
11024 //section version info
11025
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11026 {
11027 new_return(2);
11028 }
11029
11030
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11031 {
11032 new_return(3);
11033 }
11034
11035
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11036 {
11037 12 fake_pack_writing=(writecycle==0);
11038
11039 //section size
11040
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11041 {
11042 new_return(4);
11043 }
11044
11045 12 writesize=0;
11046
11047 //finally... section data
11048
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
11049 {
11050 new_return(5);
11051 }
11052
11053
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(Header->data_flags[ZQ_CHEATS2])
11054 {
11055
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zcheats.flags,f))
11056 {
11057 new_return(6);
11058 }
11059
11060
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
11061 {
11062 new_return(7);
11063 }
11064 12 }
11065
11066
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
11067 {
11068 6 section_size=writesize;
11069 6 }
11070 12 }
11071
11072
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11073 {
11074 char ebuf[80];
11075 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11076 jwin_alert("Error: writecheats()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11077 }
11078
11079 6 new_return(0);
11080 }
11081
11082 6 int32_t writeguys(PACKFILE *f, zquestheader *Header)
11083 {
11084 //these are here to bypass compiler warnings about unused arguments
11085 6 Header=Header;
11086
11087 6 dword section_id=ID_GUYS;
11088 6 dword section_version=V_GUYS;
11089 6 dword section_cversion=CV_GUYS;
11090 6 dword section_size=0;
11091
11092 //section id
11093
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11094 {
11095 new_return(1);
11096 }
11097
11098 //section version info
11099
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11100 {
11101 new_return(2);
11102 }
11103
11104
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
11105 {
11106 new_return(3);
11107 }
11108
11109
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11110 {
11111 12 fake_pack_writing=(writecycle==0);
11112
11113 //section size
11114
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11115 {
11116 new_return(4);
11117 }
11118
11119 12 writesize=0;
11120
11121 //finally... section data
11122
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<MAXGUYS; i++)
11123 {
11124
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite((char *)guy_string[i], 64, f))
11125 {
11126 new_return(5);
11127 }
11128 6144 }
11129
11130
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<MAXGUYS; i++)
11131 {
11132 6144 uint32_t flags1 = uint32_t(guysbuf[i].flags);
11133 6144 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
11134
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(flags1, f))
11135 {
11136 new_return(6);
11137 }
11138
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(flags2, f))
11139 {
11140 new_return(7);
11141 }
11142
11143
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].tile,f))
11144 {
11145 new_return(8);
11146 }
11147
11148
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].width,f))
11149 {
11150 new_return(9);
11151 }
11152
11153
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].height,f))
11154 {
11155 new_return(10);
11156 }
11157
11158
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].s_tile,f))
11159 {
11160 new_return(11);
11161 }
11162
11163
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].s_width,f))
11164 {
11165 new_return(12);
11166 }
11167
11168
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].s_height,f))
11169 {
11170 new_return(13);
11171 }
11172
11173
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].e_tile,f))
11174 {
11175 new_return(14);
11176 }
11177
11178
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].e_width,f))
11179 {
11180 new_return(15);
11181 }
11182
11183
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].e_height,f))
11184 {
11185 new_return(16);
11186 }
11187
11188
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].hp,f))
11189 {
11190 new_return(17);
11191 }
11192
11193
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].family,f))
11194 {
11195 new_return(18);
11196 }
11197
11198
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].cset,f))
11199 {
11200 new_return(19);
11201 }
11202
11203
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].anim,f))
11204 {
11205 new_return(20);
11206 }
11207
11208
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].e_anim,f))
11209 {
11210 new_return(21);
11211 }
11212
11213
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].frate,f))
11214 {
11215 new_return(22);
11216 }
11217
11218
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].e_frate,f))
11219 {
11220 new_return(23);
11221 }
11222
11223
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].dp,f))
11224 {
11225 new_return(24);
11226 }
11227
11228
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].wdp,f))
11229 {
11230 new_return(25);
11231 }
11232
11233
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].weapon,f))
11234 {
11235 new_return(26);
11236 }
11237
11238
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].rate,f))
11239 {
11240 new_return(27);
11241 }
11242
11243
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].hrate,f))
11244 {
11245 new_return(28);
11246 }
11247
11248
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].step,f))
11249 {
11250 new_return(29);
11251 }
11252
11253
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].homing,f))
11254 {
11255 new_return(30);
11256 }
11257
11258
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].grumble,f))
11259 {
11260 new_return(31);
11261 }
11262
11263
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].item_set,f))
11264 {
11265 new_return(32);
11266 }
11267
11268
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[0], f))
11269 {
11270 new_return(33);
11271 }
11272
11273
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[1],f))
11274 {
11275 new_return(34);
11276 }
11277
11278
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[2],f))
11279 {
11280 new_return(35);
11281 }
11282
11283
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[3],f))
11284 {
11285 new_return(36);
11286 }
11287
11288
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[4],f))
11289 {
11290 new_return(37);
11291 }
11292
11293
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[5],f))
11294 {
11295 new_return(38);
11296 }
11297
11298
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[6],f))
11299 {
11300 new_return(39);
11301 }
11302
11303
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[7],f))
11304 {
11305 new_return(40);
11306 }
11307
11308
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[8],f))
11309 {
11310 new_return(41);
11311 }
11312
11313
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[9],f))
11314 {
11315 new_return(42);
11316 }
11317
11318
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].bgsfx,f))
11319 {
11320 new_return(43);
11321 }
11322
11323
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].bosspal,f))
11324 {
11325 new_return(44);
11326 }
11327
11328
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].extend,f))
11329 {
11330 new_return(45);
11331 }
11332
11333
2/2
✓ Branch 0 taken 116736 times.
✓ Branch 1 taken 6144 times.
122880 for(int32_t j=0; j < edefLAST; j++)
11334 {
11335
1/2
✓ Branch 0 taken 116736 times.
✗ Branch 1 not taken.
116736 if(!p_putc(guysbuf[i].defense[j],f))
11336 {
11337 new_return(46);
11338 }
11339 116736 }
11340
11341
4/6
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4096 times.
✓ Branch 3 taken 2048 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4096 times.
6144 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11342 {
11343 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11344 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11345 //Force SFX_HIT here.
11346
11347 }
11348
11349
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].hitsfx,f))
11350 {
11351 new_return(47);
11352 }
11353
11354
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].deadsfx,f))
11355 {
11356 new_return(48);
11357 }
11358
11359
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[10],f))
11360 {
11361 new_return(49);
11362 }
11363
11364
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[11],f))
11365 {
11366 new_return(50);
11367 }
11368
11369 //New 2.6 defences
11370
2/2
✓ Branch 0 taken 135168 times.
✓ Branch 1 taken 6144 times.
141312 for(int32_t j=edefLAST; j < edefLAST255; j++)
11371 {
11372
1/2
✓ Branch 0 taken 135168 times.
✗ Branch 1 not taken.
135168 if(!p_putc(guysbuf[i].defense[j],f))
11373 {
11374 new_return(51);
11375 }
11376 135168 }
11377
11378 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11379
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].txsz,f))
11380 {
11381 new_return(52);
11382 }
11383
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].tysz,f))
11384 {
11385 new_return(53);
11386 }
11387
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hxsz,f))
11388 {
11389 new_return(54);
11390 }
11391
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hysz,f))
11392 {
11393 new_return(55);
11394 }
11395
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hzsz,f))
11396 {
11397 new_return(56);
11398 }
11399 // These are not fixed types, but ints, so they are safe to use here.
11400
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hxofs,f))
11401 {
11402 new_return(57);
11403 }
11404
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hyofs,f))
11405 {
11406 new_return(58);
11407 }
11408
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].xofs,f))
11409 {
11410 new_return(59);
11411 }
11412
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].yofs,f))
11413 {
11414 new_return(60);
11415 }
11416
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].zofs,f))
11417 {
11418 new_return(61);
11419 }
11420
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].wpnsprite,f))
11421 {
11422 new_return(62);
11423 }
11424
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].SIZEflags,f))
11425 {
11426 new_return(63);
11427 }
11428
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozentile,f))
11429 {
11430 new_return(64);
11431 }
11432
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozencset,f))
11433 {
11434 new_return(65);
11435 }
11436
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozenclock,f))
11437 {
11438 new_return(66);
11439 }
11440
11441
2/2
✓ Branch 0 taken 61440 times.
✓ Branch 1 taken 6144 times.
67584 for ( int32_t q = 0; q < 10; q++ )
11442 {
11443
1/2
✓ Branch 0 taken 61440 times.
✗ Branch 1 not taken.
61440 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11444 {
11445 new_return(67);
11446 }
11447 61440 }
11448
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].firesfx,f))
11449 {
11450 new_return(68);
11451 }
11452 //misc 16->31
11453
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[15],f))
11454 {
11455 new_return(69);
11456 }
11457
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[16],f))
11458 {
11459 new_return(70);
11460 }
11461
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[17],f))
11462 {
11463 new_return(71);
11464 }
11465
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[18],f))
11466 {
11467 new_return(72);
11468 }
11469
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[19],f))
11470 {
11471 new_return(73);
11472 }
11473
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[20],f))
11474 {
11475 new_return(74);
11476 }
11477
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[21],f))
11478 {
11479 new_return(75);
11480 }
11481
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[22],f))
11482 {
11483 new_return(76);
11484 }
11485
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[23],f))
11486 {
11487 new_return(77);
11488 }
11489
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[24],f))
11490 {
11491 new_return(78);
11492 }
11493
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[25],f))
11494 {
11495 new_return(79);
11496 }
11497
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[26],f))
11498 {
11499 new_return(80);
11500 }
11501
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[27],f))
11502 {
11503 new_return(81);
11504 }
11505
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[28],f))
11506 {
11507 new_return(82);
11508 }
11509
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[29],f))
11510 {
11511 new_return(83);
11512 }
11513
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[30],f))
11514 {
11515 new_return(84);
11516 }
11517
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[31],f))
11518 {
11519 new_return(85);
11520 }
11521
2/2
✓ Branch 0 taken 196608 times.
✓ Branch 1 taken 6144 times.
202752 for ( int32_t q = 0; q < 32; q++ )
11522 {
11523
1/2
✓ Branch 0 taken 196608 times.
✗ Branch 1 not taken.
196608 if(!p_iputl(guysbuf[i].movement[q],f))
11524 {
11525 new_return(86);
11526 }
11527 196608 }
11528
2/2
✓ Branch 0 taken 196608 times.
✓ Branch 1 taken 6144 times.
202752 for ( int32_t q = 0; q < 32; q++ )
11529 {
11530
1/2
✓ Branch 0 taken 196608 times.
✗ Branch 1 not taken.
196608 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11531 {
11532 new_return(87);
11533 }
11534 196608 }
11535
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].script,f))
11536 {
11537 new_return(88);
11538 }
11539
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11540 {
11541
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(guysbuf[i].initD[q],f))
11542 {
11543 new_return(89);
11544 }
11545 49152 }
11546
2/2
✓ Branch 0 taken 12288 times.
✓ Branch 1 taken 6144 times.
18432 for ( int32_t q = 0; q < 2; q++ )
11547 {
11548
1/2
✓ Branch 0 taken 12288 times.
✗ Branch 1 not taken.
12288 if(!p_iputl(guysbuf[i].initA[q],f))
11549 {
11550 new_return(90);
11551 }
11552 12288 }
11553
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].editorflags,f))
11554 {
11555 new_return(91);
11556 }
11557 //somehow forgot these in the older builds -Z
11558
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[12],f))
11559 {
11560 new_return(92);
11561 }
11562
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[13],f))
11563 {
11564 new_return(93);
11565 }
11566
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[14],f))
11567 {
11568 new_return(94);
11569 }
11570
11571 //Enemy Editor InitD[] labels
11572
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11573 {
11574
2/2
✓ Branch 0 taken 3194880 times.
✓ Branch 1 taken 49152 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
11575 {
11576
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11577 {
11578 new_return(95);
11579 }
11580 3194880 }
11581
2/2
✓ Branch 0 taken 3194880 times.
✓ Branch 1 taken 49152 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
11582 {
11583
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(guysbuf[i].weapon_initD_label[q][w],f))
11584 {
11585 new_return(96);
11586 }
11587 3194880 }
11588 49152 }
11589
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].weaponscript,f))
11590 {
11591 new_return(97);
11592 }
11593 //eweapon initD
11594
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11595 {
11596
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(guysbuf[i].weap_initiald[q],f))
11597 {
11598 new_return(98);
11599 }
11600 49152 }
11601
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].moveflags,f))
11602 new_return(99);
11603
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_shadow,f))
11604 new_return(100);
11605
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_death,f))
11606 new_return(101);
11607
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_spawn,f))
11608 new_return(102);
11609
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_putc(guysbuf[i].wunblockable, f))
11610 new_return(103);
11611
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].wmoveflags, f))
11612 new_return(104);
11613
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weapoverrideFLAGS, f))
11614 new_return(105);
11615
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_tilew, f))
11616 new_return(106);
11617
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_tileh, f))
11618 new_return(107);
11619
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_hxsz, f))
11620 new_return(108);
11621
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_hysz, f))
11622 new_return(109);
11623
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_hzsz, f))
11624 new_return(110);
11625
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_hxofs, f))
11626 new_return(111);
11627
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_hyofs, f))
11628 new_return(112);
11629
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_xofs, f))
11630 new_return(113);
11631
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_yofs, f))
11632 new_return(114);
11633
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].wstep, f))
11634 new_return(115);
11635
2/2
✓ Branch 0 taken 30720 times.
✓ Branch 1 taken 6144 times.
36864 for(int32_t q = 0; q < WPNSPR_MAX; ++q)
11636 {
11637
1/2
✓ Branch 0 taken 30720 times.
✗ Branch 1 not taken.
30720 if (!p_iputw(guysbuf[i].burnsprs[q], f))
11638 new_return(116 + q);
11639
1/2
✓ Branch 0 taken 30720 times.
✗ Branch 1 not taken.
30720 if (!p_iputw(guysbuf[i].light_rads[q], f))
11640 new_return(116 + WPNSPR_MAX + q);
11641 30720 }
11642 6144 }
11643
11644
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
11645 {
11646 6 section_size=writesize;
11647 6 }
11648 12 }
11649
11650
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11651 {
11652 char ebuf[80];
11653 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11654 jwin_alert("Error: writeguys()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11655 }
11656
11657 6 new_return(0);
11658 6 }
11659
11660 6 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11661 {
11662 //these are here to bypass compiler warnings about unused arguments
11663 6 Header=Header;
11664
11665 6 dword section_id=ID_HEROSPRITES;
11666 6 dword section_version=V_HEROSPRITES;
11667 6 dword section_cversion=CV_HEROSPRITES;
11668 6 dword section_size=0;
11669
11670 //section id
11671
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11672 {
11673 new_return(1);
11674 }
11675
11676 //section version info
11677
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11678 {
11679 new_return(2);
11680 }
11681
11682
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11683 {
11684 new_return(3);
11685 }
11686
11687
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11688 {
11689 12 fake_pack_writing=(writecycle==0);
11690
11691 //section size
11692
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11693 {
11694 new_return(4);
11695 }
11696
11697 12 writesize=0;
11698
11699 //finally... section data
11700
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11701 {
11702
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(walkspr[i][spr_tile],f))
11703 {
11704 new_return(5);
11705 }
11706
11707
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)walkspr[i][spr_flip],f))
11708 {
11709 new_return(5);
11710 }
11711
11712
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)walkspr[i][spr_extend],f))
11713 {
11714 new_return(5);
11715 }
11716 48 }
11717
11718
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11719 {
11720
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stabspr[i][spr_tile],f))
11721 {
11722 new_return(6);
11723 }
11724
11725
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stabspr[i][spr_flip],f))
11726 {
11727 new_return(6);
11728 }
11729
11730
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stabspr[i][spr_extend],f))
11731 {
11732 new_return(6);
11733 }
11734 48 }
11735
11736
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11737 {
11738
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slashspr[i][spr_tile],f))
11739 {
11740 new_return(7);
11741 }
11742
11743
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashspr[i][spr_flip],f))
11744 {
11745 new_return(7);
11746 }
11747
11748
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashspr[i][spr_extend],f))
11749 {
11750 new_return(7);
11751 }
11752 48 }
11753
11754
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11755 {
11756
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(floatspr[i][spr_tile],f))
11757 {
11758 new_return(8);
11759 }
11760
11761
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)floatspr[i][spr_flip],f))
11762 {
11763 new_return(8);
11764 }
11765
11766
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)floatspr[i][spr_extend],f))
11767 {
11768 new_return(8);
11769 }
11770 48 }
11771
11772
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11773 {
11774
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(swimspr[i][spr_tile],f))
11775 {
11776 new_return(8);
11777 }
11778
11779
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)swimspr[i][spr_flip],f))
11780 {
11781 new_return(8);
11782 }
11783
11784
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)swimspr[i][spr_extend],f))
11785 {
11786 new_return(8);
11787 }
11788 48 }
11789
11790
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11791 {
11792
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(divespr[i][spr_tile],f))
11793 {
11794 new_return(9);
11795 }
11796
11797
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)divespr[i][spr_flip],f))
11798 {
11799 new_return(9);
11800 }
11801
11802
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)divespr[i][spr_extend],f))
11803 {
11804 new_return(9);
11805 }
11806 48 }
11807
11808
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11809 {
11810
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(poundspr[i][spr_tile],f))
11811 {
11812 new_return(10);
11813 }
11814
11815
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)poundspr[i][spr_flip],f))
11816 {
11817 new_return(10);
11818 }
11819
11820
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)poundspr[i][spr_extend],f))
11821 {
11822 new_return(10);
11823 }
11824 48 }
11825
11826
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(castingspr[spr_tile],f))
11827 {
11828 new_return(11);
11829 }
11830
11831
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)castingspr[spr_flip],f))
11832 {
11833 new_return(11);
11834 }
11835
11836
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)castingspr[spr_extend],f))
11837 {
11838 new_return(11);
11839 }
11840
11841
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 12 times.
36 for(int32_t i=0; i<2; i++)
11842 {
11843
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 for(int32_t j=0; j<spr_holdmax; j++)
11844 {
11845
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(holdspr[i][j][spr_tile],f))
11846 {
11847 new_return(12);
11848 }
11849
11850
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11851 {
11852 new_return(12);
11853 }
11854
11855
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11856 {
11857 new_return(12);
11858 }
11859 72 }
11860 24 }
11861
11862
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11863 {
11864
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(jumpspr[i][spr_tile],f))
11865 {
11866 new_return(13);
11867 }
11868
11869
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11870 {
11871 new_return(13);
11872 }
11873
11874
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11875 {
11876 new_return(13);
11877 }
11878 48 }
11879
11880
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11881 {
11882
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(chargespr[i][spr_tile],f))
11883 {
11884 new_return(13);
11885 }
11886
11887
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)chargespr[i][spr_flip],f))
11888 {
11889 new_return(13);
11890 }
11891
11892
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)chargespr[i][spr_extend],f))
11893 {
11894 new_return(13);
11895 }
11896 48 }
11897
11898
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)zinit.hero_swim_speed,f))
11899 {
11900 new_return(14);
11901 }
11902
11903 //{ V_HEROSPRITES >= 7
11904
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11905 {
11906
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(frozenspr[q][spr_tile],f))
11907 new_return(15);
11908
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11909 new_return(15);
11910
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11911 new_return(15);
11912 48 }
11913
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11914 {
11915
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11916 new_return(15);
11917
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11918 new_return(15);
11919
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11920 new_return(15);
11921 48 }
11922
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11923 {
11924
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(onfirespr[q][spr_tile],f))
11925 new_return(15);
11926
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11927 new_return(15);
11928
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11929 new_return(15);
11930 48 }
11931
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11932 {
11933
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11934 new_return(15);
11935
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11936 new_return(15);
11937
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11938 new_return(15);
11939 48 }
11940
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11941 {
11942
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(diggingspr[q][spr_tile],f))
11943 new_return(15);
11944
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11945 new_return(15);
11946
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11947 new_return(15);
11948 48 }
11949
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11950 {
11951
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(usingrodspr[q][spr_tile],f))
11952 new_return(15);
11953
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11954 new_return(15);
11955
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11956 new_return(15);
11957 48 }
11958
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11959 {
11960
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(usingcanespr[q][spr_tile],f))
11961 new_return(15);
11962
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11963 new_return(15);
11964
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11965 new_return(15);
11966 48 }
11967
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11968 {
11969
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(pushingspr[q][spr_tile],f))
11970 new_return(15);
11971
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11972 new_return(15);
11973
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11974 new_return(15);
11975 48 }
11976
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11977 {
11978
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(liftingspr[q][spr_tile],f))
11979 new_return(15);
11980
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11981 new_return(15);
11982
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11983 new_return(15);
11984
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11985 new_return(15);
11986 48 }
11987
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11988 {
11989
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
11990 new_return(15);
11991
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
11992 new_return(15);
11993
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
11994 new_return(15);
11995 48 }
11996
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11997 {
11998
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stunnedspr[q][spr_tile],f))
11999 new_return(15);
12000
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
12001 new_return(15);
12002
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
12003 new_return(15);
12004 48 }
12005
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12006 {
12007
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
12008 new_return(15);
12009
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
12010 new_return(15);
12011
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
12012 new_return(15);
12013 48 }
12014
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12015 {
12016
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(drowningspr[q][spr_tile],f))
12017 new_return(15);
12018
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowningspr[q][spr_flip],f))
12019 new_return(15);
12020
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowningspr[q][spr_extend],f))
12021 new_return(15);
12022 48 }
12023
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12024 {
12025
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
12026 new_return(15);
12027
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
12028 new_return(15);
12029
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
12030 new_return(15);
12031 48 }
12032
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12033 {
12034
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(fallingspr[q][spr_tile],f))
12035 new_return(15);
12036
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)fallingspr[q][spr_flip],f))
12037 new_return(15);
12038
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)fallingspr[q][spr_extend],f))
12039 new_return(15);
12040 48 }
12041
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12042 {
12043
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(shockedspr[q][spr_tile],f))
12044 new_return(15);
12045
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shockedspr[q][spr_flip],f))
12046 new_return(15);
12047
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shockedspr[q][spr_extend],f))
12048 new_return(15);
12049 48 }
12050
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12051 {
12052
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
12053 new_return(15);
12054
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
12055 new_return(15);
12056
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
12057 new_return(15);
12058 48 }
12059
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12060 {
12061
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(pullswordspr[q][spr_tile],f))
12062 new_return(15);
12063
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
12064 new_return(15);
12065
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
12066 new_return(15);
12067 48 }
12068
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12069 {
12070
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(readingspr[q][spr_tile],f))
12071 new_return(15);
12072
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)readingspr[q][spr_flip],f))
12073 new_return(15);
12074
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)readingspr[q][spr_extend],f))
12075 new_return(15);
12076 48 }
12077
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12078 {
12079
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slash180spr[q][spr_tile],f))
12080 new_return(15);
12081
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slash180spr[q][spr_flip],f))
12082 new_return(15);
12083
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slash180spr[q][spr_extend],f))
12084 new_return(15);
12085 48 }
12086
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12087 {
12088
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slashZ4spr[q][spr_tile],f))
12089 new_return(15);
12090
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
12091 new_return(15);
12092
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
12093 new_return(15);
12094 48 }
12095
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12096 {
12097
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(dashspr[q][spr_tile],f))
12098 new_return(15);
12099
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)dashspr[q][spr_flip],f))
12100 new_return(15);
12101
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)dashspr[q][spr_extend],f))
12102 new_return(15);
12103 48 }
12104
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12105 {
12106
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(bonkspr[q][spr_tile],f))
12107 new_return(15);
12108
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)bonkspr[q][spr_flip],f))
12109 new_return(15);
12110
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)bonkspr[q][spr_extend],f))
12111 new_return(15);
12112 48 }
12113
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
12114 {
12115
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_iputl(medallionsprs[q][spr_tile],f))
12116 new_return(15);
12117
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
12118 new_return(15);
12119
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
12120 new_return(15);
12121 36 }
12122
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12123 {
12124
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimspr[q][spr_tile],f))
12125 new_return(16);
12126
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
12127 new_return(16);
12128
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
12129 new_return(16);
12130 48 }
12131
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12132 {
12133
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
12134 new_return(17);
12135
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
12136 new_return(17);
12137
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
12138 new_return(17);
12139 48 }
12140
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12141 {
12142
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
12143 new_return(17);
12144
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
12145 new_return(17);
12146
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
12147 new_return(17);
12148 48 }
12149
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12150 {
12151
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
12152 new_return(17);
12153
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
12154 new_return(17);
12155
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
12156 new_return(17);
12157 48 }
12158
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12159 {
12160
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
12161 new_return(18);
12162
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
12163 new_return(18);
12164
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
12165 new_return(18);
12166 48 }
12167
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12168 {
12169
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(hammeroffsets[q],f))
12170 new_return(19);
12171 48 }
12172
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 for(int32_t q = 0; q < 3; ++q)
12173 {
12174
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12175 new_return(20);
12176
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12177 new_return(20);
12178
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12179 new_return(20);
12180 36 }
12181
12182
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12183 {
12184 new_return(21);
12185 }
12186
12187
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12188 {
12189 new_return(21);
12190 }
12191
12192
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12193 {
12194 new_return(21);
12195 }
12196
12197
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12198 {
12199
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12200 new_return(22);
12201
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12202 new_return(22);
12203
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12204 new_return(22);
12205 48 }
12206
12207
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
12208 {
12209
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(revslashspr[i][spr_tile],f))
12210 {
12211 new_return(23);
12212 }
12213
12214
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12215 {
12216 new_return(23);
12217 }
12218
12219
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12220 {
12221 new_return(23);
12222 }
12223 48 }
12224
12225
12226
2/2
✓ Branch 0 taken 1752 times.
✓ Branch 1 taken 12 times.
1764 for (int32_t q = 0; q < wMax; q++) // Player defense values
12227 {
12228
1/2
✓ Branch 0 taken 1752 times.
✗ Branch 1 not taken.
1752 if (!p_putc(hero_defence[q], f))
12229 new_return(15);
12230 1752 }
12231 //}
12232
12233
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12234 {
12235 6 section_size=writesize;
12236 6 }
12237 12 }
12238
12239 //More data will come here
12240
12241
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12242 {
12243 char ebuf[80];
12244 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12245 jwin_alert("Error: writeherosprites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12246 }
12247
12248 6 new_return(0);
12249 }
12250
12251 6 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12252 {
12253 6 dword section_id=ID_SUBSCREEN;
12254 6 dword section_version=V_SUBSCREEN;
12255 6 dword section_cversion=CV_SUBSCREEN;
12256 6 dword section_size=0;
12257
12258 //section id
12259
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12260 {
12261 new_return(1);
12262 }
12263
12264 //section version info
12265
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12266 {
12267 new_return(2);
12268 }
12269
12270
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
12271 {
12272 new_return(3);
12273 }
12274
12275
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12276 {
12277 12 fake_pack_writing=(writecycle==0);
12278
12279 //section size
12280
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12281 {
12282 new_return(4);
12283 }
12284
12285 12 writesize=0;
12286
12287 12 byte sz = subscreens_active.size();
12288
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12289 new_return(5);
12290
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 12 times.
78 for(int32_t i=0; i<sz; i++)
12291 {
12292 66 int32_t ret = subscreens_active[i].write(f);
12293 66 fake_pack_writing=(writecycle==0);
12294
12295
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 if(ret!=0)
12296 new_return(ret);
12297 66 }
12298
12299 12 sz = subscreens_passive.size();
12300
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12301 new_return(5);
12302
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 12 times.
62 for(int32_t i=0; i<sz; i++)
12303 {
12304 50 int32_t ret = subscreens_passive[i].write(f);
12305 50 fake_pack_writing=(writecycle==0);
12306
12307
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 if(ret!=0)
12308 new_return(ret);
12309 50 }
12310
12311 12 sz = subscreens_overlay.size();
12312
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12313 new_return(5);
12314
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 for(int32_t i=0; i<sz; i++)
12315 {
12316 int32_t ret = subscreens_overlay[i].write(f);
12317 fake_pack_writing=(writecycle==0);
12318
12319 if(ret!=0)
12320 new_return(ret);
12321 }
12322
12323
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12324 {
12325 6 section_size=writesize;
12326 6 }
12327 12 }
12328
12329
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12330 {
12331 char ebuf[80];
12332 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12333 jwin_alert("Error: writesubscreens()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12334 }
12335
12336 6 new_return(0);
12337 6 }
12338
12339 extern script_data *ffscripts[NUMSCRIPTFFC];
12340 extern script_data *itemscripts[NUMSCRIPTITEM];
12341 extern script_data *guyscripts[NUMSCRIPTGUYS];
12342 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12343 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12344 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12345 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12346 extern script_data *playerscripts[NUMSCRIPTPLAYER];
12347 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12348 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12349 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12350 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12351 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12352
12353 6 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12354 {
12355 6 dword section_id = ID_FFSCRIPT;
12356 6 dword section_version = V_FFSCRIPT;
12357 6 dword section_cversion = CV_FFSCRIPT;
12358 6 dword section_size = 0;
12359 6 dword zasmmeta_version = METADATA_V;
12360 6 byte numscripts = 0;
12361 6 numscripts = numscripts; //to avoid unused variables warnings
12362
12363 //section id
12364
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12365 {
12366 new_return(1);
12367 }
12368
12369 //section version info
12370
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12371 {
12372 new_return(2);
12373 }
12374
12375
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
12376 {
12377 new_return(3);
12378 }
12379
12380
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12381 {
12382 new_return(4);
12383 }
12384
12385
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12386 {
12387 12 fake_pack_writing=(writecycle==0);
12388
12389 //section size
12390
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12391 {
12392 new_return(5);
12393 }
12394
12395 12 writesize=0;
12396
12397
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12398 {
12399 6144 int32_t ret = write_one_ffscript(f, Header, i, &ffscripts[i]);
12400 6144 fake_pack_writing=(writecycle==0);
12401
12402
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12403 {
12404 new_return(ret);
12405 }
12406 6144 }
12407
12408
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12409 {
12410 3072 int32_t ret = write_one_ffscript(f, Header, i, &itemscripts[i]);
12411 3072 fake_pack_writing=(writecycle==0);
12412
12413
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12414 {
12415 new_return(ret);
12416 }
12417 3072 }
12418
12419
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12420 {
12421 3072 int32_t ret = write_one_ffscript(f, Header, i, &guyscripts[i]);
12422 3072 fake_pack_writing=(writecycle==0);
12423
12424
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12425 {
12426 new_return(ret);
12427 }
12428 3072 }
12429
12430
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12431
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12432 {
12433 3072 int32_t ret = write_one_ffscript(f, Header, i, &fake);
12434 3072 fake_pack_writing=(writecycle==0);
12435
12436
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12437 {
12438 new_return(ret);
12439 }
12440 3072 }
12441
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12442
12443
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12444 {
12445 3072 int32_t ret = write_one_ffscript(f, Header, i, &screenscripts[i]);
12446 3072 fake_pack_writing=(writecycle==0);
12447
12448
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12449 {
12450 new_return(ret);
12451 }
12452 3072 }
12453
12454
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12455 {
12456 96 int32_t ret = write_one_ffscript(f, Header, i, &globalscripts[i]);
12457 96 fake_pack_writing=(writecycle==0);
12458
12459
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12460 {
12461 new_return(ret);
12462 }
12463 96 }
12464
12465
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTPLAYER; i++)
12466 {
12467 60 int32_t ret = write_one_ffscript(f, Header, i, &playerscripts[i]);
12468 60 fake_pack_writing=(writecycle==0);
12469
12470
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12471 {
12472 new_return(ret);
12473 }
12474 60 }
12475
12476
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12477 {
12478 3072 int32_t ret = write_one_ffscript(f, Header, i, &lwpnscripts[i]);
12479 3072 fake_pack_writing=(writecycle==0);
12480
12481
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12482 {
12483 new_return(ret);
12484 }
12485 3072 }
12486
12487
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12488 {
12489 3072 int32_t ret = write_one_ffscript(f, Header, i, &ewpnscripts[i]);
12490 3072 fake_pack_writing=(writecycle==0);
12491
12492
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12493 {
12494 new_return(ret);
12495 }
12496 3072 }
12497
12498
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12499 {
12500 3072 int32_t ret = write_one_ffscript(f, Header, i, &dmapscripts[i]);
12501 3072 fake_pack_writing=(writecycle==0);
12502
12503
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12504 {
12505 new_return(ret);
12506 }
12507 3072 }
12508
12509
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12510 {
12511 3072 int32_t ret = write_one_ffscript(f, Header, i, &itemspritescripts[i]);
12512 3072 fake_pack_writing=(writecycle==0);
12513
12514
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12515 {
12516 new_return(ret);
12517 }
12518 3072 }
12519
12520
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12521 {
12522 6144 int32_t ret = write_one_ffscript(f, Header, i, &comboscripts[i]);
12523 6144 fake_pack_writing=(writecycle==0);
12524
12525
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12526 {
12527 new_return(ret);
12528 }
12529 6144 }
12530
12531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12532 {
12533 new_return(2000);
12534 }
12535
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12536 {
12537 6144 int32_t ret = write_one_ffscript(f, Header, i, &genericscripts[i]);
12538 6144 fake_pack_writing=(writecycle==0);
12539
12540
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12541 {
12542 new_return(ret);
12543 }
12544 6144 }
12545
12546
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12547 {
12548 new_return(2001);
12549 }
12550
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12551 {
12552 3072 int32_t ret = write_one_ffscript(f, Header, i, &subscreenscripts[i]);
12553 3072 fake_pack_writing=(writecycle==0);
12554
12555
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12556 {
12557 new_return(ret);
12558 }
12559 3072 }
12560
12561
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12562 {
12563 new_return(2001);
12564 }
12565
12566
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12567 {
12568 new_return(2002);
12569 }
12570
12571 12 word numffcbindings=0;
12572
12573
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12574 {
12575
2/2
✓ Branch 0 taken 5932 times.
✓ Branch 1 taken 200 times.
6132 if(it->second.scriptname != "")
12576 {
12577 200 numffcbindings++;
12578 200 }
12579 6132 }
12580
12581
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12582 {
12583 new_return(2003);
12584 }
12585
12586
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12587 {
12588
2/2
✓ Branch 0 taken 5932 times.
✓ Branch 1 taken 200 times.
6132 if(it->second.scriptname != "")
12589 {
12590
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!p_iputw(it->first,f))
12591 {
12592 new_return(2004);
12593 }
12594
12595
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12596 {
12597 new_return(2005);
12598 }
12599
12600
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12601 {
12602 new_return(2006);
12603 }
12604 200 }
12605 6132 }
12606
12607 12 word numglobalbindings=0;
12608
12609
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12610 {
12611
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 if(it->second.scriptname != "")
12612 {
12613 24 numglobalbindings++;
12614 24 }
12615 96 }
12616
12617
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12618 {
12619 new_return(2007);
12620 }
12621
12622
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12623 {
12624
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 if(it->second.scriptname != "")
12625 {
12626
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputw(it->first,f))
12627 {
12628 new_return(2008);
12629 }
12630
12631
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12632 {
12633 new_return(2009);
12634 }
12635
12636
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12637 {
12638 new_return(2010);
12639 }
12640 24 }
12641 96 }
12642
12643 12 word numitembindings=0;
12644
12645
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12646 {
12647
2/2
✓ Branch 0 taken 3036 times.
✓ Branch 1 taken 24 times.
3060 if(it->second.scriptname != "")
12648 {
12649 24 numitembindings++;
12650 24 }
12651 3060 }
12652
12653
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12654 {
12655 new_return(2011);
12656 }
12657
12658
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12659 {
12660
2/2
✓ Branch 0 taken 3036 times.
✓ Branch 1 taken 24 times.
3060 if(it->second.scriptname != "")
12661 {
12662
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputw(it->first,f))
12663 {
12664 new_return(2012);
12665 }
12666
12667
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12668 {
12669 new_return(2013);
12670 }
12671
12672
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12673 {
12674 new_return(2014);
12675 }
12676 24 }
12677 3060 }
12678
12679 //new script types
12680 //npc scripts
12681 12 word numnpcbindings=0;
12682
12683
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12684 {
12685
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12686 {
12687 numnpcbindings++;
12688 }
12689 3060 }
12690
12691
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12692 {
12693 new_return(2015);
12694 }
12695
12696
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12697 {
12698
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12699 {
12700 if(!p_iputw(it->first,f))
12701 {
12702 new_return(2016);
12703 }
12704
12705 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12706 {
12707 new_return(2017);
12708 }
12709
12710 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12711 {
12712 new_return(2018);
12713 }
12714 }
12715 3060 }
12716
12717 //lweapon
12718
12719 12 word numlwpnbindings=0;
12720
12721
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12722 {
12723
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12724 {
12725 numlwpnbindings++;
12726 }
12727 3060 }
12728
12729
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12730 {
12731 new_return(2019);
12732 }
12733
12734
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12735 {
12736
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12737 {
12738 if(!p_iputw(it->first,f))
12739 {
12740 new_return(2020);
12741 }
12742
12743 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12744 {
12745 new_return(2021);
12746 }
12747
12748 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12749 {
12750 new_return(2022);
12751 }
12752 }
12753 3060 }
12754
12755 //////
12756
12757 //eweapon
12758
12759
12760 12 word numewpnbindings=0;
12761
12762
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12763 {
12764
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12765 {
12766 numewpnbindings++;
12767 }
12768 3060 }
12769
12770
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12771 {
12772 new_return(2023);
12773 }
12774
12775
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12776 {
12777
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12778 {
12779 if(!p_iputw(it->first,f))
12780 {
12781 new_return(2024);
12782 }
12783
12784 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12785 {
12786 new_return(2025);
12787 }
12788
12789 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12790 {
12791 new_return(2026);
12792 }
12793 }
12794 3060 }
12795
12796 //player scripts
12797 12 word numherobindings=0;
12798
12799
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12800 {
12801
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
48 if(it->second.scriptname != "")
12802 {
12803 2 numherobindings++;
12804 2 }
12805 48 }
12806
12807
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12808 {
12809 new_return(2027);
12810 }
12811
12812
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12813 {
12814
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
48 if(it->second.scriptname != "")
12815 {
12816
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12817 {
12818 new_return(2028);
12819 }
12820
12821
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12822 {
12823 new_return(2029);
12824 }
12825
12826
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12827 {
12828 new_return(2030);
12829 }
12830 2 }
12831 48 }
12832
12833 //dmap scripts
12834 12 word numdmapbindings=0;
12835
12836
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12837 {
12838
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12839 {
12840 4 numdmapbindings++;
12841 4 }
12842 3060 }
12843
12844
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12845 {
12846 new_return(2031);
12847 }
12848
12849
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12850 {
12851
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12852 {
12853
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12854 {
12855 new_return(2032);
12856 }
12857
12858
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12859 {
12860 new_return(2033);
12861 }
12862
12863
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12864 {
12865 new_return(2034);
12866 }
12867 4 }
12868 3060 }
12869
12870 //screen scripts
12871 12 word numscreenbindings=0;
12872
12873
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12874 {
12875
2/2
✓ Branch 0 taken 3044 times.
✓ Branch 1 taken 16 times.
3060 if(it->second.scriptname != "")
12876 {
12877 16 numscreenbindings++;
12878 16 }
12879 3060 }
12880
12881
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12882 {
12883 new_return(2035);
12884 }
12885
12886
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12887 {
12888
2/2
✓ Branch 0 taken 3044 times.
✓ Branch 1 taken 16 times.
3060 if(it->second.scriptname != "")
12889 {
12890
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_iputw(it->first,f))
12891 {
12892 new_return(2036);
12893 }
12894
12895
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12896 {
12897 new_return(2037);
12898 }
12899
12900
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12901 {
12902 new_return(2038);
12903 }
12904 16 }
12905 3060 }
12906 //item sprite scripts
12907 12 word numitemspritebindings=0;
12908
12909
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12910 {
12911
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12912 {
12913 numitemspritebindings++;
12914 }
12915 3060 }
12916
12917
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12918 {
12919 new_return(2039);
12920 }
12921
12922
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12923 {
12924
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12925 {
12926 if(!p_iputw(it->first,f))
12927 {
12928 new_return(2040);
12929 }
12930
12931 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12932 {
12933 new_return(2041);
12934 }
12935
12936 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12937 {
12938 new_return(2042);
12939 }
12940 }
12941 3060 }
12942
12943 //combo scripts
12944 12 word numcombobindings=0;
12945
12946
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12947 {
12948
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12949 {
12950 numcombobindings++;
12951 }
12952 6132 }
12953
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12954 {
12955 new_return(2043);
12956 }
12957
12958
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12959 {
12960
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12961 {
12962 if(!p_iputw(it->first,f))
12963 {
12964 new_return(2044);
12965 }
12966
12967 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12968 {
12969 new_return(2045);
12970 }
12971
12972 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12973 {
12974 new_return(2046);
12975 }
12976 }
12977 6132 }
12978 //subscreen scripts
12979 12 word numgenericbindings=0;
12980
12981
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12982 {
12983
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12984 {
12985 numgenericbindings++;
12986 }
12987 6132 }
12988
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
12989 {
12990 new_return(2043);
12991 }
12992
12993
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12994 {
12995
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12996 {
12997 if(!p_iputw(it->first,f))
12998 {
12999 new_return(2044);
13000 }
13001
13002 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13003 {
13004 new_return(2045);
13005 }
13006
13007 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13008 {
13009 new_return(2046);
13010 }
13011 }
13012 6132 }
13013
13014 //generic scripts
13015 12 word numsubscreenbindings=0;
13016
13017
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13018 {
13019
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
13020 {
13021 numsubscreenbindings++;
13022 }
13023 3060 }
13024
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
13025 {
13026 new_return(2047);
13027 }
13028
13029
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13030 {
13031
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
13032 {
13033 if(!p_iputw(it->first,f))
13034 {
13035 new_return(2048);
13036 }
13037
13038 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13039 {
13040 new_return(2049);
13041 }
13042
13043 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13044 {
13045 new_return(2050);
13046 }
13047 }
13048 3060 }
13049
13050
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13051 {
13052 6 section_size=writesize;
13053 6 }
13054 12 }
13055
13056
13057
13058
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13059 {
13060 char ebuf[80];
13061 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13062 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13063 }
13064
13065 6 new_return(0);
13066 //return 0; //this is just here to stomp the compiler from whining.
13067 //the irony is that it causes an "unreachable code" warning.
13068 6 }
13069
13070 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *Header, int32_t i, script_data **script)
13071 {
13072 //these are here to bypass compiler warnings about unused arguments
13073 46236 Header=Header;
13074 46236 i=i;
13075
13076
2/2
✓ Branch 0 taken 9494 times.
✓ Branch 1 taken 36742 times.
46236 size_t num_commands = (*script)->zasm_script ? (*script)->zasm_script->size : 0;
13077
13078
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputl(num_commands,f))
13079 {
13080 new_return(6);
13081 }
13082
13083 //Metadata
13084 46236 zasm_meta const& tmeta = (*script)->meta;
13085
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.zasm_v,f))
13086 {
13087 new_return(7);
13088 }
13089
13090
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.meta_v,f))
13091 {
13092 new_return(8);
13093 }
13094
13095
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.ffscript_v,f))
13096 {
13097 new_return(9);
13098 }
13099
13100
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putc((int)tmeta.script_type,f))
13101 {
13102 new_return(10);
13103 }
13104
13105
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(int32_t q = 0; q < 8; ++q)
13106 {
13107
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.run_idens[q],f))
13108 new_return(11);
13109 369888 }
13110
13111
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(int32_t q = 0; q < 8; ++q)
13112 {
13113
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putc(tmeta.run_types[q],f))
13114 {
13115 new_return(12);
13116 }
13117 369888 }
13118
13119
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putc(tmeta.flags,f))
13120 {
13121 new_return(13);
13122 }
13123
13124
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v1,f))
13125 {
13126 new_return(14);
13127 }
13128
13129
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v2,f))
13130 {
13131 new_return(15);
13132 }
13133
13134
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v3,f))
13135 {
13136 new_return(16);
13137 }
13138
13139
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v4,f))
13140 {
13141 new_return(17);
13142 }
13143
13144
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putcstr(tmeta.script_name,f))
13145 new_return(18);
13146
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46236 times.
46236 if(!p_putcstr(tmeta.author,f))
13147 new_return(19);
13148
2/2
✓ Branch 0 taken 462360 times.
✓ Branch 1 taken 46236 times.
508596 for(auto q = 0; q < 10; ++q)
13149 {
13150
1/2
✓ Branch 0 taken 462360 times.
✗ Branch 1 not taken.
462360 if(!p_putcstr(tmeta.attributes[q],f))
13151 new_return(27);
13152
1/2
✓ Branch 0 taken 462360 times.
✗ Branch 1 not taken.
462360 if(!p_putwstr(tmeta.attributes_help[q],f))
13153 new_return(28);
13154 462360 }
13155
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13156 {
13157
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.attribytes[q],f))
13158 new_return(29);
13159
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.attribytes_help[q],f))
13160 new_return(30);
13161 369888 }
13162
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13163 {
13164
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.attrishorts[q],f))
13165 new_return(31);
13166
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13167 new_return(32);
13168 369888 }
13169
2/2
✓ Branch 0 taken 739776 times.
✓ Branch 1 taken 46236 times.
786012 for(auto q = 0; q < 16; ++q)
13170 {
13171
1/2
✓ Branch 0 taken 739776 times.
✗ Branch 1 not taken.
739776 if(!p_putcstr(tmeta.usrflags[q],f))
13172 new_return(33);
13173
1/2
✓ Branch 0 taken 739776 times.
✗ Branch 1 not taken.
739776 if(!p_putwstr(tmeta.usrflags_help[q],f))
13174 new_return(34);
13175 739776 }
13176
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13177 {
13178
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.initd[q],f))
13179 new_return(35);
13180
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.initd_help[q],f))
13181 new_return(36);
13182 369888 }
13183
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13184 {
13185
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putc(tmeta.initd_type[q],f))
13186 new_return(37);
13187 369888 }
13188
13189
2/2
✓ Branch 0 taken 36742 times.
✓ Branch 1 taken 626442 times.
663184 for(int32_t j=0; j<num_commands; j++)
13190 {
13191 626442 auto& zas = (*script)->zasm_script->zasm[j];
13192
1/2
✓ Branch 0 taken 626442 times.
✗ Branch 1 not taken.
626442 if(!p_iputw(zas.command,f))
13193 {
13194 new_return(20);
13195 }
13196
13197
2/2
✓ Branch 0 taken 616948 times.
✓ Branch 1 taken 9494 times.
626442 if(zas.command==0xFFFF)
13198 {
13199 9494 break;
13200 }
13201 else
13202 {
13203
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(zas.arg1,f))
13204 {
13205 new_return(21);
13206 }
13207
13208
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(zas.arg2,f))
13209 {
13210 new_return(22);
13211 }
13212
13213
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(zas.arg3,f))
13214 {
13215 new_return(23);
13216 }
13217
13218 616948 uint32_t sz = 0;
13219
2/2
✓ Branch 0 taken 2770 times.
✓ Branch 1 taken 614178 times.
616948 if(zas.strptr)
13220 2770 sz = zas.strptr->size();
13221
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(sz,f))
13222 {
13223 new_return(23);
13224 }
13225
2/2
✓ Branch 0 taken 614178 times.
✓ Branch 1 taken 2770 times.
616948 if(sz)
13226 {
13227 2770 auto& str = *zas.strptr;
13228
2/2
✓ Branch 0 taken 222648 times.
✓ Branch 1 taken 2770 times.
225418 for(size_t q = 0; q < sz; ++q)
13229 {
13230
1/2
✓ Branch 0 taken 222648 times.
✗ Branch 1 not taken.
222648 if(!p_putc(str[q],f))
13231 {
13232 new_return(24);
13233 }
13234 222648 }
13235 2770 }
13236 616948 sz = 0;
13237
2/2
✓ Branch 0 taken 616834 times.
✓ Branch 1 taken 114 times.
616948 if(zas.vecptr)
13238 114 sz = zas.vecptr->size();
13239
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(sz,f))
13240 {
13241 new_return(25);
13242 }
13243
2/2
✓ Branch 0 taken 616834 times.
✓ Branch 1 taken 114 times.
616948 if(sz) //vector found
13244 {
13245 114 auto& vec = *zas.vecptr;
13246
2/2
✓ Branch 0 taken 850 times.
✓ Branch 1 taken 114 times.
964 for(size_t q = 0; q < sz; ++q)
13247 {
13248
1/2
✓ Branch 0 taken 850 times.
✗ Branch 1 not taken.
850 if(!p_iputl(vec[q],f))
13249 {
13250 new_return(26);
13251 }
13252 850 }
13253 114 }
13254 }
13255 616948 }
13256
13257 46236 new_return(0);
13258 }
13259
13260 extern SAMPLE customsfxdata[WAV_COUNT];
13261 extern uint8_t customsfxflag[WAV_COUNT>>3];
13262
13263 6 int32_t writesfx(PACKFILE *f, zquestheader *Header)
13264 {
13265 //these are here to bypass compiler warnings about unused arguments
13266 6 Header=Header;
13267
13268 6 dword section_id=ID_SFX;
13269 6 dword section_version=V_SFX;
13270 6 dword section_cversion=CV_SFX;
13271 6 dword section_size=0;
13272
13273 //section id
13274
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13275 {
13276 new_return(1);
13277 }
13278
13279 //section version info
13280
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13281 {
13282 new_return(2);
13283 }
13284
13285
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13286 {
13287 new_return(3);
13288 }
13289
13290
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13291 {
13292 12 fake_pack_writing=(writecycle==0);
13293
13294 //section size
13295
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13296 {
13297 new_return(4);
13298 }
13299
13300 12 writesize=0;
13301
13302
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for(int32_t i=0; i<WAV_COUNT>>3; i++)
13303 {
13304
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(customsfxflag[i],f))
13305 {
13306 new_return(5);
13307 }
13308 384 }
13309
13310
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(int32_t i=1; i<WAV_COUNT; i++)
13311 {
13312
2/2
✓ Branch 0 taken 820 times.
✓ Branch 1 taken 2240 times.
3060 if(get_bit(customsfxflag, i-1) == 0)
13313 2240 continue;
13314
13315
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!pfwrite(sfx_string[i], 36, f))
13316 {
13317 new_return(5);
13318 }
13319 820 }
13320
13321
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(int32_t i=1; i<WAV_COUNT; i++)
13322 {
13323
2/2
✓ Branch 0 taken 820 times.
✓ Branch 1 taken 2240 times.
3060 if(get_bit(customsfxflag, i-1) == 0)
13324 2240 continue;
13325
13326
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].bits,f))
13327 {
13328 new_return(5);
13329 }
13330
13331
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].stereo,f))
13332 {
13333 new_return(6);
13334 }
13335
13336
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].freq,f))
13337 {
13338 new_return(7);
13339 }
13340
13341
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].priority,f))
13342 {
13343 new_return(8);
13344 }
13345
13346
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].len,f))
13347 {
13348 new_return(9);
13349 }
13350
13351
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].loop_start,f))
13352 {
13353 new_return(10);
13354 }
13355
13356
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].loop_end,f))
13357 {
13358 new_return(11);
13359 }
13360
13361
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].param,f))
13362 {
13363 new_return(12);
13364 }
13365
13366 //de-endianfy the data
13367 820 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
13368
13369
2/2
✓ Branch 0 taken 18594894 times.
✓ Branch 1 taken 820 times.
18595714 for(int32_t j=0; j<wordstowrite; j++)
13370 {
13371
1/2
✓ Branch 0 taken 18594894 times.
✗ Branch 1 not taken.
18594894 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
13372 {
13373 new_return(13);
13374 }
13375 18594894 }
13376 820 }
13377
13378
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13379 {
13380 6 section_size=writesize;
13381 6 }
13382 12 }
13383
13384
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13385 {
13386 char ebuf[80];
13387 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13388 jwin_alert("Error: writesfx()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13389 }
13390
13391 6 new_return(0);
13392 }
13393
13394 6 int32_t writeinitdata(PACKFILE *f, zquestheader *)
13395 {
13396 6 dword section_id=ID_INITDATA;
13397 6 dword section_version=V_INITDATA;
13398 6 dword section_cversion=CV_INITDATA;
13399 6 dword section_size = 0;
13400
13401 6 zinit.last_map=Map.getCurrMap();
13402 6 zinit.last_screen=Map.getCurrScr();
13403 6 zinit.normalize();
13404
13405 //section id
13406
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13407 {
13408 new_return(1);
13409 }
13410
13411 //section version info
13412
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13413 {
13414 new_return(2);
13415 }
13416
13417
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13418 {
13419 new_return(3);
13420 }
13421
13422 //TODO
13423
13424
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13425 {
13426 12 fake_pack_writing=(writecycle==0);
13427
13428 //section size
13429
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13430 new_return(4);
13431
13432 12 writesize=0;
13433
13434
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for(int q = 0; q < MAXITEMS/8; ++q)
13435
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(zinit.items[q], f))
13436 new_return(5);
13437
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 12 times.
780 for(int q = 0; q < MAXLEVELS/8; ++q)
13438 {
13439
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.map[q], f))
13440 new_return(6);
13441
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.compass[q], f))
13442 new_return(7);
13443
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.boss_key[q], f))
13444 new_return(8);
13445
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.mcguffin[q], f))
13446 new_return(9);
13447 768 }
13448
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbvec(zinit.level_keys, f))
13449 new_return(10);
13450
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(MAX_COUNTERS,f))
13451 new_return(11);
13452
2/2
✓ Branch 0 taken 1284 times.
✓ Branch 1 taken 12 times.
1296 for(int q = 0; q < MAX_COUNTERS; ++q)
13453
1/2
✓ Branch 0 taken 1284 times.
✗ Branch 1 not taken.
1284 if(!p_iputw(zinit.counter[q],f))
13454 new_return(12);
13455
2/2
✓ Branch 0 taken 1284 times.
✓ Branch 1 taken 12 times.
1296 for(int q = 0; q < MAX_COUNTERS; ++q)
13456
1/2
✓ Branch 0 taken 1284 times.
✗ Branch 1 not taken.
1284 if(!p_iputw(zinit.mcounter[q],f))
13457 new_return(13);
13458
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.bomb_ratio,f))
13459 new_return(14);
13460
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hcp,f))
13461 new_return(15);
13462
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hcp_per_hc,f))
13463 new_return(16);
13464
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.cont_heart,f))
13465 new_return(17);
13466
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hp_per_heart,f))
13467 new_return(18);
13468
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.magic_per_block,f))
13469 new_return(19);
13470
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_damage_multiplier,f))
13471 new_return(20);
13472
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.ene_damage_multiplier,f))
13473 new_return(21);
13474
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_type,f))
13475 new_return(22);
13476
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_arg,f))
13477 new_return(23);
13478
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_percent,f))
13479 new_return(24);
13480
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.def_lightrad,f))
13481 new_return(25);
13482
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.transdark_percent,f))
13483 new_return(26);
13484
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.darkcol,f))
13485 new_return(27);
13486
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_x,f))
13487 new_return(28);
13488
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_y,f))
13489 new_return(29);
13490
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_xofs,f))
13491 new_return(30);
13492
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_yofs,f))
13493 new_return(31);
13494
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_color,f))
13495 new_return(32);
13496
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_bbox_1_color,f))
13497 new_return(33);
13498
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_bbox_2_color,f))
13499 new_return(34);
13500
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_flags,f))
13501 new_return(35);
13502
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbitstr(zinit.flags,f))
13503 new_return(36);
13504
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.last_map,f))
13505 new_return(37);
13506
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.last_screen,f))
13507 new_return(38);
13508
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_x,f))
13509 new_return(39);
13510
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_y,f))
13511 new_return(40);
13512
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_is_offset,f))
13513 new_return(41);
13514
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_speed,f))
13515 new_return(42);
13516
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.gravity,f))
13517 new_return(43);
13518
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.swimgravity,f))
13519 new_return(44);
13520
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.terminalv,f))
13521 new_return(45);
13522
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_speed,f))
13523 new_return(46);
13524
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_mult,f))
13525 new_return(47);
13526
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_div,f))
13527 new_return(48);
13528
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimUpStep,f))
13529 new_return(49);
13530
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimSideStep,f))
13531 new_return(50);
13532
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimDownStep,f))
13533 new_return(51);
13534
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.exitWaterJump,f))
13535 new_return(52);
13536
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroStep,f))
13537 new_return(53);
13538
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.heroAnimationStyle,f))
13539 new_return(54);
13540
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.jump_hero_layer_threshold,f))
13541 new_return(55);
13542
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.bunny_ltm,f))
13543 new_return(56);
13544
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.start_dmap,f))
13545 new_return(57);
13546
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.subscrSpeed,f))
13547 new_return(58);
13548
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.switchhookstyle,f))
13549 new_return(59);
13550
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.magicdrainrate,f))
13551 new_return(60);
13552
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputzf(zinit.shove_offset,f))
13553 new_return(61);
13554
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbitstr(zinit.gen_doscript, f))
13555 new_return(62);
13556
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_exitState, f))
13557 new_return(63);
13558
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_reloadState, f))
13559 new_return(64);
13560
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_initd, f))
13561 new_return(65);
13562
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_eventstate, f))
13563 new_return(66);
13564
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_data, f))
13565 new_return(67);
13566
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.screen_data, f))
13567 new_return(68);
13568
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickerspeed, f))
13569 new_return(69);
13570
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickercolor, f))
13571 new_return(70);
13572
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickertransp, f))
13573 new_return(71);
13574
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_iputzf(zinit.air_drag, f))
13575 new_return(72);
13576
13577
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13578 {
13579 6 section_size=writesize;
13580 6 }
13581 12 }
13582
13583
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13584 {
13585 char ebuf[80];
13586 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13587 jwin_alert("Error: writeinitdata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13588 }
13589
13590 6 new_return(0);
13591 }
13592
13593 6 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
13594 {
13595 //these are here to bypass compiler warnings about unused arguments
13596 6 Header=Header;
13597
13598 6 dword section_id=ID_ITEMDROPSETS;
13599 6 dword section_version=V_ITEMDROPSETS;
13600 6 dword section_cversion=CV_ITEMDROPSETS;
13601 // dword section_size=0;
13602 6 dword section_size = 0;
13603 6 word num_item_drop_sets=count_item_drop_sets();
13604
13605 //section id
13606
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13607 {
13608 new_return(1);
13609 }
13610
13611 //section version info
13612
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13613 {
13614 new_return(2);
13615 }
13616
13617
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13618 {
13619 new_return(3);
13620 }
13621
13622
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13623 {
13624 12 fake_pack_writing=(writecycle==0);
13625
13626 //section size
13627
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13628 {
13629 new_return(4);
13630 }
13631
13632 12 writesize=0;
13633
13634 //finally... section data
13635
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(num_item_drop_sets,f))
13636 {
13637 new_return(5);
13638 }
13639
13640
2/2
✓ Branch 0 taken 158 times.
✓ Branch 1 taken 12 times.
170 for(int32_t i=0; i<num_item_drop_sets; i++)
13641 {
13642
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
13643 {
13644 new_return(6);
13645 }
13646
13647
2/2
✓ Branch 0 taken 1580 times.
✓ Branch 1 taken 158 times.
1738 for(int32_t j=0; j<10; ++j)
13648 {
13649
1/2
✓ Branch 0 taken 1580 times.
✗ Branch 1 not taken.
1580 if(!p_iputw(item_drop_sets[i].item[j],f))
13650 {
13651 new_return(7);
13652 }
13653 1580 }
13654
13655
2/2
✓ Branch 0 taken 1738 times.
✓ Branch 1 taken 158 times.
1896 for(int32_t j=0; j<11; ++j)
13656 {
13657
1/2
✓ Branch 0 taken 1738 times.
✗ Branch 1 not taken.
1738 if(!p_iputw(item_drop_sets[i].chance[j],f))
13658 {
13659 new_return(8);
13660 }
13661 1738 }
13662 158 }
13663
13664
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13665 {
13666 6 section_size=writesize;
13667 6 }
13668 12 }
13669
13670
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13671 {
13672 char ebuf[80];
13673 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13674 jwin_alert("Error: writeitemdropsets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13675 }
13676
13677 6 new_return(0);
13678 }
13679
13680 6 int32_t writefavorites(PACKFILE *f, zquestheader*)
13681 {
13682 6 dword section_id=ID_FAVORITES;
13683 6 dword section_version=V_FAVORITES;
13684 6 dword section_cversion=CV_FAVORITES;
13685 6 dword section_size = 0;
13686
13687 //section id
13688
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13689 {
13690 new_return(1);
13691 }
13692
13693 //section version info
13694
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13695 {
13696 new_return(2);
13697 }
13698
13699
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13700 {
13701 new_return(3);
13702 }
13703
13704
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13705 {
13706 12 fake_pack_writing=(writecycle==0);
13707
13708 //section size
13709
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13710 new_return(4);
13711
13712 12 writesize=0;
13713
13714
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
13715 new_return(16);
13716
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
13717 new_return(17);
13718
13719 12 word favcmb_cnt = 0;
13720
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 14918 times.
14922 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
13721
2/2
✓ Branch 0 taken 14910 times.
✓ Branch 1 taken 8 times.
14918 if(favorite_combos[q] != -1)
13722 {
13723 8 favcmb_cnt = q+1;
13724 8 break;
13725 }
13726
13727
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
13728 new_return(5);
13729
13730
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 12 times.
222 for(int i=0; i<favcmb_cnt; ++i)
13731 {
13732
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 if (!p_putc(favorite_combo_modes[i], f))
13733 new_return(6);
13734
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 if (!p_iputl(favorite_combos[i], f))
13735 new_return(7);
13736 210 }
13737
13738
13739 12 word max_combo_cols = MAX_COMBO_COLS;
13740
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(max_combo_cols,f))
13741 new_return(9);
13742
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int q = 0; q < max_combo_cols; ++q)
13743 {
13744
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(First[q],f))
13745 new_return(10);
13746
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(combo_alistpos[q],f))
13747 new_return(11);
13748
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(combo_pool_listpos[q],f))
13749 new_return(12);
13750 48 }
13751 12 word max_mappages = MAX_MAPPAGE_BTNS;
13752
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(max_mappages,f))
13753 new_return(13);
13754
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 12 times.
120 for(int q = 0; q < max_mappages; ++q)
13755 {
13756
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(map_page[q].map,f))
13757 new_return(14);
13758
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(map_page[q].screen,f))
13759 new_return(15);
13760 108 }
13761
13762
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13763 {
13764 6 section_size=writesize;
13765 6 }
13766 12 }
13767
13768
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13769 {
13770 char ebuf[80];
13771 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13772 jwin_alert("Error: writefavorites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13773 }
13774
13775 6 new_return(0);
13776 }
13777
13778 6 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
13779 {
13780
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!afname) afname = filename;
13781 6 reset_combo_animations();
13782 6 reset_combo_animations2();
13783 6 strcpy(header.id_str,QH_NEWIDSTR);
13784 6 header.zelda_version = ZELDA_VERSION;
13785 6 header.internal = INTERNAL_VERSION;
13786 // header.str_count = msg_count;
13787 // header.data_flags[ZQ_TILES] = usetiles;
13788 6 header.data_flags[ZQ_TILES] = true;
13789 6 header.data_flags[ZQ_CHEATS2] = 1;
13790 6 header.build=VERSION_BUILD;
13791
13792
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 6 times.
1518 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
13793 {
13794 1512 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
13795 1512 }
13796
13797 char zinfofilename[2048];
13798 6 replace_extension(zinfofilename, afname, "zinfo", 2047);
13799
13800 6 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
13801 6 box_out("Saving Quest...");
13802 6 box_eol();
13803 6 box_eol();
13804
13805
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 std::string tmp_filename = util::create_temp_file_path(filename);
13806
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
13807
13808
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!f)
13809 return 1;
13810
13811
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Header...");
13812
13813
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeheader(f,&header)!=0)
13814 return 2;
13815
13816
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13817
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13818
13819
13820
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(header.external_zinfo)
13821 {
13822 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
13823
13824 box_out("Writing ZInfo...");
13825 if(inf)
13826 {
13827 if(writezinfo(inf,ZI)!=0)
13828 return 2;
13829
13830 pack_fclose(inf);
13831 box_out("okay.");
13832 }
13833 else box_out(" ...file failure");
13834 box_eol();
13835 }
13836 else
13837 {
13838
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing ZInfo...");
13839
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writezinfo(f,ZI)!=0)
13840 return 2;
13841
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13842
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13843 }
13844
13845
13846
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Rules...");
13847
13848
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writerules(f,&header)!=0)
13849 return 3;
13850
13851
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13852
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13853
13854
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Strings...");
13855
13856
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
13857 return 4;
13858
13859
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13860
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13861
13862
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Doors...");
13863
13864
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writedoorcombosets(f,&header)!=0)
13865 return 5;
13866
13867
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13868
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13869
13870
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing DMaps...");
13871
13872
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
13873 return 6;
13874
13875
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13876
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13877
13878
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing &QMisc. Data...");
13879
13880
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writemisc(f,&header)!=0)
13881 return 7;
13882
13883
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13884
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13885
13886
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing &QMisc. Colors...");
13887
13888
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writemisccolors(f,&header)!=0)
13889 return 8;
13890
13891
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13892
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13893
13894
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Game Icons...");
13895
13896
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writegameicons(f,&header)!=0)
13897 return 9;
13898
13899
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13900
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13901
13902
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Items...");
13903
13904
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeitems(f,&header)!=0)
13905 return 10;
13906
13907
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13908
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13909
13910
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Weapons...");
13911
13912
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeweapons(f,&header)!=0)
13913 return 11;
13914
13915
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13916
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13917
13918
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Maps...");
13919
13920
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writemaps(f,&header)!=0)
13921 return 12;
13922
13923
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13924
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13925
13926
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Combos...");
13927
13928
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
13929 return 13;
13930
13931
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13932
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13933
13934
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Combo Aliases...");
13935
13936
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
13937 return 14;
13938
13939
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13940
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13941
13942
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Color Data...");
13943
13944
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
13945 return 15;
13946
13947
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13948
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13949
13950
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Tiles...");
13951
13952
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
13953 return 16;
13954
13955
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13956
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13957
13958
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing MIDIs...");
13959
13960
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writemidis(f)!=0)
13961 return 17;
13962
13963
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13964
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13965
13966
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Cheat Codes...");
13967
13968
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writecheats(f,&header)!=0)
13969 return 18;
13970
13971
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13972
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13973
13974
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Init. Data...");
13975
13976
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeinitdata(f,&header)!=0)
13977 return 19;
13978
13979
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13980
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13981
13982
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Guy Data...");
13983
13984
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeguys(f,&header)!=0)
13985 return 20;
13986
13987
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13988
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13989
13990
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Player Sprite Data...");
13991
13992
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeherosprites(f,&header)!=0)
13993 return 21;
13994
13995
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13996
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13997
13998
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Subscreen Data...");
13999
14000
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writesubscreens(f,&header)!=0)
14001 return 22;
14002
14003
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14004
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14005
14006
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing FF Script Data...");
14007
14008
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeffscript(f,&header)!=0)
14009 return 23;
14010
14011
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14012
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14013
14014
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing SFX Data...");
14015
14016
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writesfx(f,&header)!=0)
14017 return 24;
14018
14019
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14020
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14021
14022
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Item Drop Sets...");
14023
14024
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeitemdropsets(f, &header)!=0)
14025 return 25;
14026
14027
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14028
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14029
14030
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Favorite Combos...");
14031
14032
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writefavorites(f, &header)!=0)
14033 return 26;
14034
14035
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14036
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14037
14038
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 pack_fclose(f);
14039
14040
14041
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
6 if(header.use_keyfile&&header.dirty_password)
14042 {
14043 char const* kfname = filename;
14044 char keyfilename[2048]={0};
14045 zprint2("Writing key files for '%s'\n", kfname, ".zpwd", ".zcheat");
14046
14047 char temp_pw[QSTPWD_LEN] = {0};
14048 uint ind = 0;
14049 for(char const* ext : {"key","zpwd","zcheat"})
14050 {
14051 replace_extension(keyfilename, kfname, ext, 2047);
14052 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
14053 char msg[80] = {0};
14054 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
14055 msg[78]=13;
14056 msg[79]=10;
14057 pfwrite(msg, 80, fp);
14058 p_iputw(header.zelda_version,fp);
14059 p_putc(header.build,fp);
14060 char const* pwd = header.password;
14061 if(ind == 2) //.zcheat, hashed pwd
14062 {
14063 char hashmap = 'Z';
14064 hashmap += 'Q';
14065 hashmap += 'U';
14066 hashmap += 'E';
14067 hashmap += 'S';
14068 hashmap += 'T';
14069 for ( int q = 0; q < QSTPWD_LEN; ++q )
14070 {
14071 temp_pw[q] = header.password[q];
14072 temp_pw[q] += hashmap;
14073 }
14074 pwd = temp_pw;
14075 }
14076 pfwrite(pwd, strlen(pwd), fp);
14077 pack_fclose(fp);
14078 ++ind;
14079 }
14080 }
14081
14082 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
14083 6 std::error_code ec;
14084
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 fs::rename(tmp_filename, filename, ec);
14085
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (ec)
14086 {
14087 al_trace("Error saving: %s\n", std::strerror(ec.value()));
14088 return ec.value();
14089 }
14090
14091
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
14092
14093 #ifdef __EMSCRIPTEN__
14094 em_sync_fs();
14095 #endif
14096
14097 6 return 0;
14098 6 }
14099
14100 // #ifdef _WIN32
14101 // static std::time_t to_time_t(FILETIME const& ft) {
14102 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14103 // t -= 116444736000000000ull;
14104 // t /= 10000000u;
14105 // return static_cast<std::time_t>(t);
14106 // }
14107 // #else
14108 // #endif
14109 template<typename TP>
14110 4 static std::time_t to_time_t(TP tp) {
14111 using namespace std::chrono;
14112 4 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14113 4 return system_clock::to_time_t(sctp);
14114 }
14115
14116 4 std::string get_time_last_modified_string(std::string path)
14117 {
14118
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 auto write_time = fs::last_write_time(path);
14119 // TODO: C++20 but not supported yet.
14120 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14121 4 std::time_t tt = to_time_t(write_time);
14122 4 std::tm *gmt = std::gmtime(&tt);
14123 4 std::stringstream buffer;
14124
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 buffer << std::put_time(gmt, "%Y-%m-%d");
14125
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 std::string formattedFileTime = buffer.str();
14126 4 return formattedFileTime;
14127
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 }
14128
14129 6 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14130 {
14131 // Always backup quest if it was last saved in a different version of the editor,
14132 // or if this a new file and is overwritting another qst file.
14133
10/16
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
6 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14134 {
14135 4 std::string backup_name;
14136
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 std::string last_mod = get_time_last_modified_string(filename);
14137
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (strlen(header.zelda_version_string) > 0)
14138 {
14139
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14140 4 }
14141 else
14142 {
14143 backup_name = fmt::format("{}", last_mod);
14144 }
14145
7/14
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
4 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14146
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 fs::path backup_path = fs::path("backups") / backup_fname;
14147
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 if (!fs::exists(backup_path))
14148 {
14149
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 fs::create_directories(fs::path("backups"));
14150
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 if (fs::copy_file(filename, backup_path))
14151 {
14152
5/10
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 4 times.
4 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14153 4 }
14154 else
14155 {
14156 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14157 }
14158 4 }
14159 4 }
14160
14161 6 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14162 6 fake_pack_writing = false;
14163
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(ret)
14164 {
14165 box_out("-- Error saving quest file! --");
14166 box_end(true);
14167 }
14168 6 else box_end(false);
14169 6 return ret;
14170 }
14171
14172 6 int32_t save_quest(const char *filename, bool timed_save)
14173 {
14174
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14175
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 bool compress=!(timed_save&&UncompressedAutoSaves);
14176 char ext1[5];
14177 6 ext1[0]=0;
14178
14179
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(timed_save)
14180 {
14181 sprintf(ext1, "qt");
14182 }
14183 else
14184 {
14185 6 sprintf(ext1, "qb");
14186 }
14187
14188
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(retention)
14189 {
14190 char backupname[2048];
14191 char backupname2[2048];
14192 char ext[12];
14193
14194 for(int32_t i=retention-1; i>0; --i)
14195 {
14196 sprintf(ext, "%s%d", ext1, i-1);
14197 replace_extension(backupname, filepath, ext, 2047);
14198
14199 if(exists(backupname))
14200 {
14201 sprintf(ext, "%s%d", ext1, i);
14202 replace_extension(backupname2, filepath, ext, 2047);
14203
14204 if(exists(backupname2))
14205 {
14206 remove(backupname2);
14207 }
14208
14209 rename(backupname, backupname2);
14210 }
14211 }
14212
14213 //don't do this if we're not saving to the same name -DD
14214 if(!timed_save && !strcmp(filepath, filename))
14215 {
14216 sprintf(ext, "%s%d", ext1, 0);
14217 replace_extension(backupname, filepath, ext, 2047);
14218 rename(filepath, backupname);
14219 }
14220 }
14221
14222 int32_t ret;
14223 6 ret = save_unencoded_quest(filename, compress, filename);
14224
14225 6 return ret;
14226 }
14227
14228 6 void center_zq_class_dialogs()
14229 {
14230 6 jwin_center_dialog(pwd_dlg);
14231 6 }
14232
14233 void zmap::prv_secrets(bool high16only)
14234 {
14235 mapscr *s = &prvscr;
14236 mapscr *t = prvlayers;
14237 int32_t ft=0;
14238
14239 for(int32_t i=0; i<176; i++)
14240 {
14241 bool putit;
14242
14243 if(!high16only)
14244 {
14245 for(int32_t j=-1; j<6; j++)
14246 {
14247 int32_t newflag = -1;
14248
14249 for(int32_t iter=0; iter<2; ++iter)
14250 {
14251 putit=true;
14252
14253 if(!t[j].valid)
14254 continue;
14255
14256 int32_t checkflag=combobuf[t[j].data[i]].flag;
14257
14258 if(iter==1)
14259 {
14260 checkflag=t[j].sflag[i];
14261 }
14262
14263 switch(checkflag)
14264 {
14265 case mfANYFIRE:
14266 ft=sBCANDLE;
14267 break;
14268
14269 case mfSTRONGFIRE:
14270 ft=sRCANDLE;
14271 break;
14272
14273 case mfMAGICFIRE:
14274 ft=sWANDFIRE;
14275 break;
14276
14277 case mfDIVINEFIRE:
14278 ft=sDIVINEFIRE;
14279 break;
14280
14281 case mfARROW:
14282 ft=sARROW;
14283 break;
14284
14285 case mfSARROW:
14286 ft=sSARROW;
14287 break;
14288
14289 case mfGARROW:
14290 ft=sGARROW;
14291 break;
14292
14293 case mfSBOMB:
14294 ft=sSBOMB;
14295 break;
14296
14297 case mfBOMB:
14298 ft=sBOMB;
14299 break;
14300
14301 case mfBRANG:
14302 ft=sBRANG;
14303 break;
14304
14305 case mfMBRANG:
14306 ft=sMBRANG;
14307 break;
14308
14309 case mfFBRANG:
14310 ft=sFBRANG;
14311 break;
14312
14313 case mfWANDMAGIC:
14314 ft=sWANDMAGIC;
14315 break;
14316
14317 case mfREFMAGIC:
14318 ft=sREFMAGIC;
14319 break;
14320
14321 case mfREFFIREBALL:
14322 ft=sREFFIREBALL;
14323 break;
14324
14325 case mfSWORD:
14326 ft=sSWORD;
14327 break;
14328
14329 case mfWSWORD:
14330 ft=sWSWORD;
14331 break;
14332
14333 case mfMSWORD:
14334 ft=sMSWORD;
14335 break;
14336
14337 case mfXSWORD:
14338 ft=sXSWORD;
14339 break;
14340
14341 case mfSWORDBEAM:
14342 ft=sSWORDBEAM;
14343 break;
14344
14345 case mfWSWORDBEAM:
14346 ft=sWSWORDBEAM;
14347 break;
14348
14349 case mfMSWORDBEAM:
14350 ft=sMSWORDBEAM;
14351 break;
14352
14353 case mfXSWORDBEAM:
14354 ft=sXSWORDBEAM;
14355 break;
14356
14357 case mfHOOKSHOT:
14358 ft=sHOOKSHOT;
14359 break;
14360
14361 case mfWAND:
14362 ft=sWAND;
14363 break;
14364
14365 case mfHAMMER:
14366 ft=sHAMMER;
14367 break;
14368
14369 case mfSTRIKE:
14370 ft=sSTRIKE;
14371 break;
14372
14373 default:
14374 putit = false;
14375 break;
14376 }
14377
14378 if(putit)
14379 {
14380 if(j==-1)
14381 {
14382 s->data[i] = s->secretcombo[ft];
14383 s->cset[i] = s->secretcset[ft];
14384 newflag = s->secretflag[ft];
14385 }
14386 else
14387 {
14388 t[j].data[i] = t[j].secretcombo[ft];
14389 t[j].cset[i] = t[j].secretcset[ft];
14390 newflag = t[j].secretflag[ft];
14391 }
14392 }
14393 }
14394
14395 if(newflag >-1)
14396 {
14397 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
14398 }
14399 }
14400 }
14401
14402 //if(true)
14403 //{
14404 int32_t newflag = -1;
14405
14406 for(int32_t iter=0; iter<2; ++iter)
14407 {
14408 int32_t checkflag=combobuf[s->data[i]].flag;
14409
14410 if(iter==1)
14411 {
14412 checkflag=s->sflag[i];
14413 }
14414
14415 if((checkflag > 15)&&(checkflag < 32))
14416 {
14417 s->data[i] = s->secretcombo[(checkflag)-16+4];
14418 s->cset[i] = s->secretcset[(checkflag)-16+4];
14419 newflag = s->secretflag[(checkflag)-16+4];
14420 // putit = true;
14421 }
14422 }
14423
14424 if(newflag >-1) s->sflag[i] = newflag;
14425
14426 for(int32_t j=0; j<6; j++)
14427 {
14428 if(!t[j].valid) continue;
14429
14430 int32_t newflag2 = -1;
14431
14432 for(int32_t iter=0; iter<2; ++iter)
14433 {
14434 int32_t checkflag=combobuf[t[j].data[i]].flag;
14435
14436 if(iter==1)
14437 {
14438 checkflag=t[j].sflag[i];
14439 }
14440
14441 if((checkflag > 15)&&(checkflag < 32))
14442 {
14443 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
14444 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
14445 newflag2 = t[j].secretflag[(checkflag)-16+4];
14446 }
14447 }
14448
14449 if(newflag2 >-1) t[j].sflag[i] = newflag2;
14450 }
14451 }
14452
14453 //FFCs
14454 word c = s->numFFC();
14455 for(word i=0; i<c; ++i)
14456 {
14457 bool putit;
14458
14459 if(!high16only)
14460 {
14461 for(int32_t iter=0; iter<1; ++iter)
14462 {
14463 putit=true;
14464 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
14465
14466 if(iter==1)
14467 {
14468 checkflag=s->sflag[i];
14469 }
14470
14471 switch(checkflag)
14472 {
14473 case mfANYFIRE:
14474 ft=sBCANDLE;
14475 break;
14476
14477 case mfSTRONGFIRE:
14478 ft=sRCANDLE;
14479 break;
14480
14481 case mfMAGICFIRE:
14482 ft=sWANDFIRE;
14483 break;
14484
14485 case mfDIVINEFIRE:
14486 ft=sDIVINEFIRE;
14487 break;
14488
14489 case mfARROW:
14490 ft=sARROW;
14491 break;
14492
14493 case mfSARROW:
14494 ft=sSARROW;
14495 break;
14496
14497 case mfGARROW:
14498 ft=sGARROW;
14499 break;
14500
14501 case mfSBOMB:
14502 ft=sSBOMB;
14503 break;
14504
14505 case mfBOMB:
14506 ft=sBOMB;
14507 break;
14508
14509 case mfBRANG:
14510 ft=sBRANG;
14511 break;
14512
14513 case mfMBRANG:
14514 ft=sMBRANG;
14515 break;
14516
14517 case mfFBRANG:
14518 ft=sFBRANG;
14519 break;
14520
14521 case mfWANDMAGIC:
14522 ft=sWANDMAGIC;
14523 break;
14524
14525 case mfREFMAGIC:
14526 ft=sREFMAGIC;
14527 break;
14528
14529 case mfREFFIREBALL:
14530 ft=sREFFIREBALL;
14531 break;
14532
14533 case mfSWORD:
14534 ft=sSWORD;
14535 break;
14536
14537 case mfWSWORD:
14538 ft=sWSWORD;
14539 break;
14540
14541 case mfMSWORD:
14542 ft=sMSWORD;
14543 break;
14544
14545 case mfXSWORD:
14546 ft=sXSWORD;
14547 break;
14548
14549 case mfSWORDBEAM:
14550 ft=sSWORDBEAM;
14551 break;
14552
14553 case mfWSWORDBEAM:
14554 ft=sWSWORDBEAM;
14555 break;
14556
14557 case mfMSWORDBEAM:
14558 ft=sMSWORDBEAM;
14559 break;
14560
14561 case mfXSWORDBEAM:
14562 ft=sXSWORDBEAM;
14563 break;
14564
14565 case mfHOOKSHOT:
14566 ft=sHOOKSHOT;
14567 break;
14568
14569 case mfWAND:
14570 ft=sWAND;
14571 break;
14572
14573 case mfHAMMER:
14574 ft=sHAMMER;
14575 break;
14576
14577 case mfSTRIKE:
14578 ft=sSTRIKE;
14579 break;
14580
14581 default:
14582 putit = false;
14583 break;
14584 }
14585
14586 if(putit)
14587 {
14588 s->ffcs[i].data = s->secretcombo[ft];
14589 s->ffcs[i].cset = s->secretcset[ft];
14590 }
14591 }
14592 }
14593
14594 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
14595 {
14596 for(int32_t iter=0; iter<1; ++iter)
14597 {
14598 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
14599
14600 if(iter==1)
14601 {
14602 // FFCs can't have flags! Yet...
14603 }
14604
14605 if((checkflag > 15)&&(checkflag < 32))
14606 {
14607 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
14608 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
14609 }
14610 }
14611 }
14612 }
14613 }
14614